Becoming an extern "Qt" block #147
Replies: 6 comments 5 replies
-
For signals instead use an attribute on the enum which defines which type they should be declared on. Note that there can only be one signals definition per QObject. (it would work having multiple enums as we just do a match and then call the relevant method, but if two enums had a signal with the same name it'd break). #[signals(MyObject)]
enum MyObjectSignals {
Ready,
DataChanged { first: i32, second: QPoint },
} |
Beta Was this translation helpful? Give feedback.
-
We can also specify if we need an override in the invokable attribute impl MyObject {
#[invokable(override)]
fn invokable(self: Pin<&Self>) {
...
}
} And if the C++ class needs any includes we can specify these as normal includes like CXX unsafe extern "Qt" {
include!("path/to/header.h");
// can we also specify ones from the system
include!("QVector"); // eg this would be #include <QVector> ?
} |
Beta Was this translation helpful? Give feedback.
-
If we can avoid needing to store the CppObj inside the struct (and rewriting it) this will feel much more natural. Instead if we could have the update_requester / signal emission available as implementations on the QObject this would be much easier. impl MyObject {
pub fn update_requester(self: Pin<&mut Self>) -> UpdateRequester { ... }
} This could work by having a global hashmap singleton that as Rust objects are created or dropped a map from the RustObj -> CppObj is created. Then in methods such as the update_requester it can call something like |
Beta Was this translation helpful? Give feedback.
-
Wonder if we should call the Rust and C++ sides with unique names, so that when developers extend the interface with their own extern Rust or C++ blocks it's obvious what they are doing. Eg extern "Qt" {
struct MyObject {
...
}
...
} Would generate the following output extern "C++" {
type MyObjectCpp;
fn newCppObject() -> UniquePtr<MyObjectCpp>;
}
extern "Rust" {
type MyObjectRust = super::MyObject;
fn prop(self: Pin<&MyObjectRust>) -> &T;
} Then in the C++ we create the class called class MyObjectCpp : public QObject {
...
};
typedef MyObjectCpp MyObject; This then has the advantage that within the CXX extern C++ / Rust blocks the typename used would be MyObjectCpp or MyObjectRust, which results in very explicit typing. Whereas the previous suggestion would result in "MyObject" being used which is not as clear which side of the bridge this refers to. |
Beta Was this translation helpful? Give feedback.
-
Also see: #156 |
Beta Was this translation helpful? Give feedback.
-
This is effectively implemented now, closing. |
Beta Was this translation helpful? Give feedback.
-
Requirements
Solutions
Use an
extern "Qt"
block where we define anything we want to become a QObject, note that the scope of anything define inside it moves outside of the bridge.Developer code
Generated Code
Problems
Beta Was this translation helpful? Give feedback.
All reactions