@@ -68,6 +68,9 @@ mod ffi {
68
68
69
69
#[ namespace = "rust::cxxqtlib1" ]
70
70
unsafe extern "C++" {
71
+ include ! ( "cxx-qt-lib/common.h" ) ;
72
+ type c_void = crate :: c_void ;
73
+
71
74
#[ doc( hidden) ]
72
75
#[ rust_name = "qqmlapplicationengine_new" ]
73
76
fn qqmlapplicationengineNew ( ) -> UniquePtr < QQmlApplicationEngine > ;
@@ -79,6 +82,20 @@ mod ffi {
79
82
) -> Pin < & mut QQmlEngine > ;
80
83
}
81
84
85
+ #[ cfg( any( cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5) ) ]
86
+ unsafe extern "C++" {
87
+ include ! ( "cxx-qt-lib/qanystringview.h" ) ;
88
+ type QAnyStringView < ' a > = crate :: QAnyStringView < ' a > ;
89
+ }
90
+
91
+ #[ namespace = "rust::cxxqtlib1" ]
92
+ #[ cfg( any( cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5) ) ]
93
+ unsafe extern "C++" {
94
+ #[ doc( hidden) ]
95
+ #[ rust_name = "qqmlapplicationengine_singleton_instance" ]
96
+ fn qqmlapplicationengineSingletonInstance ( ptr : Pin < & mut QQmlApplicationEngine > , uri : QAnyStringView , typeName : QAnyStringView ) -> * mut c_void ;
97
+ }
98
+
82
99
// QQmlApplicationEngine is not a trivial to CXX and is not relocatable in Qt
83
100
// as the following fails in C++. So we cannot mark it as a trivial type
84
101
// and need to use references or pointers.
@@ -87,6 +104,8 @@ mod ffi {
87
104
}
88
105
89
106
use crate :: QQmlEngine ;
107
+ #[ cfg( any( cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5) ) ]
108
+ use crate :: QAnyStringView ;
90
109
use core:: pin:: Pin ;
91
110
92
111
pub use ffi:: QQmlApplicationEngine ;
@@ -101,4 +120,17 @@ impl QQmlApplicationEngine {
101
120
pub fn new ( ) -> cxx:: UniquePtr < Self > {
102
121
ffi:: qqmlapplicationengine_new ( )
103
122
}
123
+
124
+ /// Returns the instance of a singleton type named typeName from the module specified by uri.
125
+ /// This function was introduced in Qt 6.5.
126
+ #[ cfg( any( cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5) ) ]
127
+ pub fn singleton_instance < T > ( self : Pin < & mut Self > , uri : QAnyStringView , type_name : QAnyStringView ) -> Option < & mut T > {
128
+ unsafe {
129
+ let ptr = ffi:: qqmlapplicationengine_singleton_instance ( self , uri, type_name) ;
130
+ if ptr. is_null ( ) {
131
+ return None ;
132
+ }
133
+ Some ( & mut * ( ptr as * mut T ) )
134
+ }
135
+ }
104
136
}
0 commit comments