Skip to content

Commit fbc99fe

Browse files
committed
cxx-qt-gen: always include QQmlEngine for QML and add include to moc
This allows for moc to read the .cxx.h for other includes
1 parent 560b0fa commit fbc99fe

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

crates/cxx-qt-build/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ impl CxxQtBuilder {
733733
{
734734

735735
let mut moc_arguments = moc_arguments.clone();
736+
// Ensure that header root is in the include path of moc
737+
// otherwise it cannot read the .cxx.h paths
738+
moc_arguments = moc_arguments.include_path(dir::header_root());
739+
736740
if let Some(qml_module) = &self.qml_module {
737741
// Ensure that the generated QObject header is in the include path
738742
// so that qmltyperegistar can include them later

crates/cxx-qt-gen/src/generator/cpp/qobject.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ impl GeneratedCppQObjectBlocks {
6262

6363
pub fn from(qobject: &ParsedQObject) -> GeneratedCppQObjectBlocks {
6464
let mut qml_specifiers = Vec::new();
65-
let mut includes = BTreeSet::new();
6665
if let Some(qml_metadata) = &qobject.qml_metadata {
67-
// When specifying the QML declarative macros moc needs the header to be
68-
// included, otherwise it does not understand what these expand to.
69-
includes.insert("#include <QtQml/QQmlEngine>".to_string());
66+
// Note ensure that the header moc processes has QtQml/QQmlEngine
67+
// this is done via generator/rust/qobject
7068

7169
qml_specifiers.push(format!("QML_NAMED_ELEMENT({})", qml_metadata.name));
7270

@@ -79,7 +77,6 @@ impl GeneratedCppQObjectBlocks {
7977
}
8078
}
8179
GeneratedCppQObjectBlocks {
82-
includes,
8380
metaobjects: qml_specifiers,
8481
..Default::default()
8582
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ impl GeneratedRustFragment {
4040
generate_rust_signals(&structured_qobject.signals, &qobject_names, type_names)?,
4141
];
4242

43-
// If this type is a singleton then we need to add an include
44-
if let Some(qml_metadata) = &qobject.qml_metadata {
45-
if qml_metadata.singleton {
46-
generated.push(GeneratedRustFragment::from_cxx_item(parse_quote! {
47-
unsafe extern "C++" {
48-
include!(<QtQml/QQmlEngine>);
49-
}
50-
}))
51-
}
43+
// If this type is using QML declarative macros then ensure we have the right include
44+
if qobject.qml_metadata.is_some() {
45+
generated.push(GeneratedRustFragment::from_cxx_item(parse_quote! {
46+
unsafe extern "C++" {
47+
include!(<QtQml/QQmlEngine>);
48+
}
49+
}))
5250
}
5351

5452
// If this type has threading enabled then add generation

0 commit comments

Comments
 (0)