Skip to content

Commit 2161557

Browse files
Add more signals
- Add objectCreated signal to QQmlApplicationEngine - Add objectCreationFailed signal to QQmlApplicationEngine - Fixed bug where type_name doesn't recognise QObject - Fixed qualification of QCoreApplication in bridge
1 parent b0759c2 commit 2161557

File tree

8 files changed

+110
-28
lines changed

8 files changed

+110
-28
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- CXX-Qt-build: Allow forcing initialization of crates/QML modules (`cxx_qt::init_crate!`/`cxx_qt::init_qml_module!`)
3030
- Add pure virtual function specified through the `#[cxx_pure]` attribute
3131
- Add wrappers for up and down casting, for all types which inherit from QObject, available for &T, &mut T and Pin<&mut T>
32+
- `#[base = T]` is now suported in `extern "C++Qt"` blocks
33+
- Casting is automatically implmented for qobjects or types which have `#[base = T]` in `"RustQt"` or `"C++Qt"` blocks
3234
- Support for `QMessageLogContext` and sending log messages to the Qt message handler.
3335

3436
### Removed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub fn generate_rust_signal(
127127
if !signal.private {
128128
cxx_mod_contents.push(parse_quote_spanned! {
129129
span=>
130+
#(#cfgs)*
130131
#unsafety_block extern "C++" {
131132
#[cxx_name = #cpp_ident]
132133
#(#cfgs)*
@@ -144,22 +145,27 @@ pub fn generate_rust_signal(
144145
unsafe extern "C++" {
145146
#[doc(hidden)]
146147
#[namespace = #namespace_str]
148+
#(#cfgs)*
147149
type #signal_handler_alias = cxx_qt::signalhandler::CxxQtSignalHandler<super::#closure_struct>;
148150

149151
#[doc(hidden)]
150152
#[namespace = #namespace_str]
151153
#[cxx_name = #free_connect_ident_cpp]
154+
#(#cfgs)*
152155
fn #free_connect_ident_rust(self_value: #self_type_cxx, signal_handler: #signal_handler_alias, conn_type: CxxQtConnectionType) -> CxxQtQMetaObjectConnection;
153156
}
154157
},
155158
parse_quote_spanned! {
156159
span=>
157160
#[namespace = #namespace_str]
161+
#(#cfgs)*
158162
extern "Rust" {
159163
#[doc(hidden)]
164+
#(#cfgs)*
160165
fn #signal_handler_drop(handler: #signal_handler_alias);
161166

162167
#[doc(hidden)]
168+
#(#cfgs)*
163169
#unsafe_call fn #signal_handler_call(handler: &mut #signal_handler_alias, self_value: #self_type_cxx, #(#parameters_cxx),*);
164170
}
165171
}]);
@@ -174,6 +180,7 @@ pub fn generate_rust_signal(
174180
#[doc = "Connect the given function pointer to the signal "]
175181
#[doc = #signal_name_cpp]
176182
#[doc = ", so that when the signal is emitted the function pointer is executed."]
183+
#(#cfgs)*
177184
pub fn #connect_ident_rust<F: FnMut(#self_type_qualified, #(#parameters_qualified_type),*) + 'static + Send>(self: #self_type_qualified, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
178185
{
179186
cxx_qt::QMetaObjectConnectionGuard::from(#module_ident::#free_connect_ident_rust(
@@ -193,6 +200,7 @@ pub fn generate_rust_signal(
193200
#[doc = ", so that when the signal is emitted the function pointer is executed."]
194201
#[doc = "\n"]
195202
#[doc = "Note that this method uses a AutoConnection connection type."]
203+
#(#cfgs)*
196204
pub fn #on_ident_rust<F: FnMut(#self_type_qualified, #(#parameters_qualified_type),*) + 'static + Send>(self: #self_type_qualified, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
197205
{
198206
cxx_qt::QMetaObjectConnectionGuard::from(#module_ident::#free_connect_ident_rust(
@@ -213,7 +221,9 @@ pub fn generate_rust_signal(
213221
span =>
214222
#(#cfgs)*
215223
impl cxx_qt::signalhandler::CxxQtSignalHandlerClosure for #closure_struct {
224+
#(#cfgs)*
216225
type Id = cxx::type_id!(#signal_handler_alias_namespaced_str);
226+
#(#cfgs)*
217227
type FnType = dyn FnMut(#self_type_qualified, #(#parameters_qualified_type),*) + Send;
218228
}
219229
},

crates/cxx-qt-gen/src/naming/type_names.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ impl TypeNames {
119119
type_names.populate_from_cxx_items(cxx_items, bridge_namespace, module_ident)?;
120120
type_names.populate_from_cxx_qt_data(cxx_qt_data, bridge_namespace, module_ident)?;
121121

122+
let qobject = Name {
123+
rust: format_ident!("QObject"),
124+
cxx: None,
125+
module: Some(Path::from(module_ident.clone())),
126+
namespace: None,
127+
};
128+
type_names.names.insert(qobject.rust.clone(), qobject);
129+
122130
Ok(type_names)
123131
}
124132

crates/cxx-qt-gen/src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ mod tests {
396396
assert_eq!(parser.passthrough_module.vis, Visibility::Inherited);
397397
assert_eq!(parser.cxx_qt_data.namespace, Some("cxx_qt".to_owned()));
398398
assert_eq!(parser.cxx_qt_data.qobjects.len(), 1);
399-
assert_eq!(parser.type_names.num_types(), 18);
399+
assert_eq!(parser.type_names.num_types(), 19);
400400
assert_eq!(
401401
parser
402402
.type_names
@@ -501,7 +501,7 @@ mod tests {
501501
}
502502
};
503503
let parser = Parser::from(module).unwrap();
504-
assert_eq!(parser.type_names.num_types(), 22);
504+
assert_eq!(parser.type_names.num_types(), 23);
505505
assert_eq!(
506506
parser
507507
.type_names

0 commit comments

Comments
 (0)