Skip to content

Commit 1e80af7

Browse files
BenFordTytheringtonahayzen-kdab
authored andcommitted
Add more signals to cxx_qt_lib
- Add objectCreated signal to QQmlApplicationEngine - Fixed bug where type_name doesn't recognise QObject - Fixed qualification of QCoreApplication in bridge
1 parent b0759c2 commit 1e80af7

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

CHANGELOG.md

+2
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/naming/type_names.rs

+8
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

+2-2
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

crates/cxx-qt-lib/src/core/qcoreapplication.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::{QByteArray, QString, QStringList, QVector};
88
use core::pin::Pin;
99

10-
#[cxx::bridge]
10+
#[cxx_qt::bridge]
1111
mod ffi {
1212
unsafe extern "C++" {
1313
include!("cxx-qt-lib/qbytearray.h");
@@ -30,6 +30,13 @@ mod ffi {
3030
fn qcoreapplicationNew(args: &QVector_QByteArray) -> UniquePtr<QCoreApplication>;
3131
}
3232

33+
unsafe extern "C++Qt" {
34+
#[doc(hidden)]
35+
#[rust_name = "about_to_quit"]
36+
#[qsignal]
37+
pub(self) fn aboutToQuit(self: Pin<&mut QCoreApplication>);
38+
}
39+
3340
// These are all static, so we need to create bindings until CXX supports statics
3441
#[namespace = "rust::cxxqtlib1"]
3542
unsafe extern "C++" {

crates/cxx-qt-lib/src/gui/qguiapplication.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod ffi {
2222
type QFont = crate::QFont;
2323

2424
include!("cxx-qt-lib/qcoreapplication.h");
25-
type QCoreApplication;
25+
type QCoreApplication = crate::QCoreApplication;
2626
}
2727

2828
unsafe extern "C++Qt" {

crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ mod ffi {
6565
type QQmlApplicationEngine;
6666
}
6767

68+
unsafe extern "C++Qt" {
69+
#[qsignal]
70+
#[rust_name = "object_created"]
71+
unsafe fn objectCreated(
72+
self: Pin<&mut QQmlApplicationEngine>,
73+
qobject: *mut QObject,
74+
url: &QUrl,
75+
);
76+
}
77+
6878
unsafe extern "C++" {
6979
include!("cxx-qt-lib/qqmlengine.h");
7080
type QQmlEngine = crate::QQmlEngine;

0 commit comments

Comments
 (0)