Skip to content

Commit a02ef71

Browse files
Add Transitive casting and testing code
1 parent 723ba1e commit a02ef71

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

crates/cxx-qt-gen/src/generator/rust/fragment.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ impl GeneratedRustFragment {
8383
#upcast_fn_qualified(this)
8484
}
8585

86-
unsafe fn from_base_ptr(base: *const #base_qualified) -> *const Self {
87-
#downcast_fn_qualified(base)
86+
unsafe fn from_base_ptr(base: *const #base_qualified) -> *const Self {
87+
#downcast_fn_qualified(base)
88+
}
8889
}
89-
}
90-
}],
90+
},
91+
// Add back once we figure out the bug with QObject, for automatic transitive casts
92+
// parse_quote! {
93+
// unsafe impl ::cxx_qt::MainCast for #struct_name {
94+
// type Base = #base_qualified;
95+
// }
96+
// }
97+
],
9198
})
9299
}
93100

examples/qml_minimal/qml/main.qml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ ApplicationWindow {
2828
string: qsTr("My String with my number: %1").arg(myObject.number)
2929
}
3030

31+
A {
32+
id: a
33+
number: 10
34+
}
35+
3136
Column {
3237
anchors.fill: parent
3338
anchors.margins: 10
@@ -55,6 +60,12 @@ ApplicationWindow {
5560
onClicked: myObject.sayHi(myObject.string, myObject.number)
5661
}
5762

63+
Button {
64+
text: qsTr("Test A")
65+
66+
onClicked: a.test()
67+
}
68+
5869
Button {
5970
text: qsTr("Quit")
6071

0 commit comments

Comments
 (0)