Nested QObjects and MyObjectQt API #237
-
With our move to a more direct integration with CXX and our new API changes, we have to think about how to represent Nested QObjects in future and how they should be defined in CXX-Qt. What works and what doesn'tWe should do the least amount of work to make nested objects work, such that the integration with existing CXX features is as clear and flexible as possible. Things that already work out-of-the-box:
Which means we mostly have means to refer to ownership (UniquePtr, vs. Pin<&mut>) within a cxx-qt defined QObject. What we have to figure out:
Referring to a foreign QObjectThis issue has two targets:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Why not swap the default?Instead of trying to teach people that we auto-generate a new MyObjectQt type, why not instead generate a MyObjectRust type, and simply make MyObject the QObject type. We can then still use associated types to give you access to the MyObjectRust type in a sane way. So example of associated types: pub trait CxxQtObject {
type Rust; // or maybe Inner?
}
impl CxxQtObject for MyObject {
type Rust = MyObjectRust;
} Then you could use the inner type as: <MyObject as CxxQtObject>::Rust |
Beta Was this translation helpful? Give feedback.
-
Swap the names around
|
Beta Was this translation helpful? Give feedback.
-
Swapping the types creates a really nice API, however it has the fun of
|
Beta Was this translation helpful? Give feedback.
-
Suggestion: Using ModulesIdea: Make a Problems:We can't have a module that contains a struct named MyObject, as well as a module named MyObject: pub struct MyStruct {
pub x: i32,
}
mod MyStruct {
pub struct QObject {
pub y: i32,
}
} Solution 1Alternatively, we could have a MyStruct module, with a #[cxx_qt::qobject]
struct MyStruct {
#[qproperty]
pub x: i32
}
// replaced by cxx-qt with:
mod MyStruct {
pub struct Rust {
pub x: i32,
}
type QObject = MyStructQt
} Solution 2Maybe we could create a QObject module instead: #[cxx_qt::qobject]
struct MyStruct {
#[qproperty]
x: i32,
}
// generated by cxx-qt
#[allow(non_snake_case)]
mod QObject {
type MyStruct = MyStructQt
} This would allow you to refer to:
|
Beta Was this translation helpful? Give feedback.
Suggestion: Using Modules
Idea: Make a
MyObject
Module, that contains a QObject type.That would allow for a syntax of
MyObject::QObject
to refer to the QObject version of the struct.Problems:
We can't have a module that contains a struct named MyObject, as well as a module named MyObject:
e.g., this doesn't compile:
Solution 1
Alternatively, we could have a MyStruct module, with a
Rust
and aQObject
struct in it.Even though that's also syntactically somewhat strange.