woboq / qmetaobject-rs

Integrate Qml and Rust by building the QMetaObject at compile time.
MIT License
647 stars 89 forks source link

Wrapping existing QObjects? #290

Open Supreeeme opened 1 year ago

Supreeeme commented 1 year ago

The guidance in the README seems to be around creating your own QObjects from Rust. But is there any way to wrap a QObject in Qt's library that isn't currently in qmetaobject? Namely, I'm interested in being able to connect to their signals/slots, and as far as I'm aware cpp_class! does not provide this.

ogoffart commented 1 year ago

There is the current doc for that: https://github.com/woboq/qmetaobject-rs#what-if-a-wrapper-for-the-qt-c-api-is-missing And you can look at the source code of the crate for examples.

Supreeeme commented 1 year ago

The example in the docs seems to show creating a new QObject from Rust, but I want to use one that already exists from C++. I see the QObjects that come with the library are wrapped withcpp_class!, but none of them implement the QObject trait. Is it possible to get an implementation of this trait for something wrapped with cpp_class!?