File tree 3 files changed +30
-4
lines changed
qml_multi_crates/rust/main/src
3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,28 @@ pub trait Upcast<T> {
267
267
}
268
268
}
269
269
270
+ impl < T > Upcast < T > for T {
271
+ unsafe fn upcast_ptr ( this : * const Self ) -> * const Self {
272
+ this
273
+ }
274
+
275
+ unsafe fn from_base_ptr ( base : * const T ) -> * const Self {
276
+ base
277
+ }
278
+
279
+ fn upcast ( & self ) -> & Self {
280
+ self
281
+ }
282
+
283
+ fn upcast_mut ( & mut self ) -> & mut Self {
284
+ self
285
+ }
286
+
287
+ fn upcast_pin ( self : Pin < & mut Self > ) -> Pin < & mut Self > {
288
+ self
289
+ }
290
+ }
291
+
270
292
/// This trait is automatically implemented by CXX-Qt and you most likely do not need to manually implement it.
271
293
/// Trait for downcasting to a subclass, provided the subclass implements [Upcast] to this type.
272
294
/// Returns `None` in cases where `Sub` isn't a child class of `Self`.
Original file line number Diff line number Diff line change 14
14
// ANCHOR: book_cargo_imports
15
15
pub mod cxxqt_object;
16
16
17
+ use std:: pin:: Pin ;
18
+
17
19
use cxx_qt:: Upcast ;
18
- use cxx_qt_lib:: { QGuiApplication , QQmlApplicationEngine , QUrl } ;
20
+ use cxx_qt_lib:: { QGuiApplication , QQmlApplicationEngine , QQmlEngine , QUrl } ;
19
21
// ANCHOR_END: book_cargo_imports
20
22
21
23
// ANCHOR: book_cargo_rust_main
@@ -30,9 +32,9 @@ fn main() {
30
32
}
31
33
32
34
if let Some ( engine) = engine. as_mut ( ) {
35
+ let engine: Pin < & mut QQmlEngine > = engine. upcast_pin ( ) ;
33
36
// Listen to a signal from the QML Engine
34
37
engine
35
- . upcast_pin ( )
36
38
. on_quit ( |_| {
37
39
println ! ( "QML Quit!" ) ;
38
40
} )
Original file line number Diff line number Diff line change 5
5
6
6
extern crate qml_multi_crates;
7
7
8
+ use std:: pin:: Pin ;
9
+
8
10
use cxx_qt:: Upcast ;
9
- use cxx_qt_lib:: { QGuiApplication , QQmlApplicationEngine , QUrl } ;
11
+ use cxx_qt_lib:: { QGuiApplication , QQmlApplicationEngine , QQmlEngine , QUrl } ;
10
12
11
13
fn main ( ) {
12
14
cxx_qt:: init_crate!( qml_multi_crates) ;
@@ -21,9 +23,9 @@ fn main() {
21
23
}
22
24
23
25
if let Some ( engine) = engine. as_mut ( ) {
26
+ let engine: Pin < & mut QQmlEngine > = engine. upcast_pin ( ) ;
24
27
// Listen to a signal from the QML Engine
25
28
engine
26
- . upcast_pin ( )
27
29
. on_quit ( |_| {
28
30
println ! ( "QML Quit!" ) ;
29
31
} )
You can’t perform that action at this time.
0 commit comments