@@ -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,13 +82,33 @@ 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 (
97
+ ptr : Pin < & mut QQmlApplicationEngine > ,
98
+ uri : QAnyStringView ,
99
+ typeName : QAnyStringView ,
100
+ ) -> * mut c_void ;
101
+ }
102
+
82
103
// QQmlApplicationEngine is not a trivial to CXX and is not relocatable in Qt
83
104
// as the following fails in C++. So we cannot mark it as a trivial type
84
105
// and need to use references or pointers.
85
106
// static_assert(QTypeInfo<QQmlApplicationEngine>::isRelocatable);
86
107
impl UniquePtr < QQmlApplicationEngine > { }
87
108
}
88
109
110
+ #[ cfg( any( cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5) ) ]
111
+ use crate :: QAnyStringView ;
89
112
use crate :: QQmlEngine ;
90
113
use core:: pin:: Pin ;
91
114
@@ -101,4 +124,21 @@ impl QQmlApplicationEngine {
101
124
pub fn new ( ) -> cxx:: UniquePtr < Self > {
102
125
ffi:: qqmlapplicationengine_new ( )
103
126
}
127
+
128
+ /// Returns the instance of a singleton type named typeName from the module specified by uri.
129
+ /// This function was introduced in Qt 6.5.
130
+ #[ cfg( any( cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5) ) ]
131
+ pub fn singleton_instance < T > (
132
+ self : Pin < & mut Self > ,
133
+ uri : QAnyStringView ,
134
+ type_name : QAnyStringView ,
135
+ ) -> Option < & mut T > {
136
+ unsafe {
137
+ let ptr = ffi:: qqmlapplicationengine_singleton_instance ( self , uri, type_name) ;
138
+ if ptr. is_null ( ) {
139
+ return None ;
140
+ }
141
+ Some ( & mut * ( ptr as * mut T ) )
142
+ }
143
+ }
104
144
}
0 commit comments