rust-qt / ritual

Use C++ libraries from Rust
Apache License 2.0
1.22k stars 49 forks source link

missing `invokeMethod` function for `QMetaObject` #130

Open melvyn2 opened 1 year ago

melvyn2 commented 1 year ago

https://doc.qt.io/qt-5/qmetaobject.html#invokeMethod I need to call invokeMethod from a non-GUI thread to trigger an object's slot in the GUI thread. The recommended method seems to be to use that object's meta-object invokeMethod function. However I cannot find this method in the qt_core bindings. What is missing for its implementation?

Riateche commented 1 year ago

We're missing support for the QGenericArgument type, which is constructed in C++ using the Q_ARG macro. It's possible to add support for it for a finite set of types, but it hasn't been done yet.

As a workaround, you can use a queued signal-slot connection (see Signals and Slots Across Threads). When using a queued connection, Qt will automatically invoke slots in the receiver's thread. You can use a signal wrapper type provided by rust-qt to create a sender object.

melvyn2 commented 1 year ago

I was aware of using queued connections but I hadn't found the signal wrapper types. That solves my problem, thank you.

I'll leave the issue open in case it is eventually decided to implement invokeMethod.