-
Notifications
You must be signed in to change notification settings - Fork 92
Add support for C++ QML Elements in CxxQtBuilder #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -377,6 +377,7 @@ pub struct CxxQtBuilder { | |||||
include_prefix: String, | ||||||
crate_include_root: Option<String>, | ||||||
additional_include_dirs: Vec<PathBuf>, | ||||||
qml_qobjects: Vec<(PathBuf, PathBuf)>, | ||||||
} | ||||||
|
||||||
impl CxxQtBuilder { | ||||||
|
@@ -418,6 +419,7 @@ impl CxxQtBuilder { | |||||
include_prefix: crate_name(), | ||||||
crate_include_root: Some(String::new()), | ||||||
additional_include_dirs: vec![], | ||||||
qml_qobjects: vec![], | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -588,6 +590,22 @@ impl CxxQtBuilder { | |||||
self | ||||||
} | ||||||
|
||||||
/// Specify a C++ header and source file containing a Q_OBJECT macro to run [moc](https://doc.qt.io/qt-6/moc.html) on. | ||||||
/// Unlike [CxxQtBuilder::qobject_header], it includes the generated metatypes.json, so that C++ classes can be included | ||||||
/// in QML modules. | ||||||
pub fn qml_qobject( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
mut self, | ||||||
qobject_header: impl AsRef<Path>, | ||||||
qobject_source: impl AsRef<Path>, | ||||||
) -> Self { | ||||||
let qobject_header = qobject_header.as_ref().to_path_buf(); | ||||||
let qobject_source = qobject_source.as_ref().to_path_buf(); | ||||||
println!("cargo::rerun-if-changed={}", qobject_header.display()); | ||||||
println!("cargo::rerun-if-changed={}", qobject_source.display()); | ||||||
self.qml_qobjects.push((qobject_header, qobject_source)); | ||||||
self | ||||||
} | ||||||
|
||||||
/// Use a closure to run additional customization on [CxxQtBuilder]'s internal [cc::Build] | ||||||
/// before calling [CxxQtBuilder::build]. This allows to add extra include paths, compiler flags, | ||||||
/// or anything else available via [cc::Build]'s API. For example, to add an include path for | ||||||
|
@@ -869,6 +887,22 @@ impl CxxQtBuilder { | |||||
} | ||||||
} | ||||||
|
||||||
for (qobject_header, qobject_source) in &self.qml_qobjects { | ||||||
cc_builder.file(qobject_source); | ||||||
if let Some(dir) = qobject_header.parent() { | ||||||
moc_include_paths.insert(dir.to_path_buf()); | ||||||
} | ||||||
let moc_products = qtbuild.moc().compile( | ||||||
qobject_header, | ||||||
MocArguments::default().uri(qml_module.uri.clone()), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
); | ||||||
if let Some(dir) = moc_products.cpp.parent() { | ||||||
moc_include_paths.insert(dir.to_path_buf()); | ||||||
} | ||||||
cc_builder.file(moc_products.cpp); | ||||||
qml_metatypes_json.push(moc_products.metatypes_json); | ||||||
} | ||||||
|
||||||
let qml_module_registration_files = qtbuild.register_qml_module( | ||||||
&qml_metatypes_json, | ||||||
&qml_module.uri, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should clarify the difference between this method and
qobject_header
more explicitly. Currently it only mentions that it 'includes the generated metatypes.json' but doesn't explain when to use each method.Copilot uses AI. Check for mistakes.