diff --git a/Cargo.toml b/Cargo.toml index 805948259..196f4b4c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "examples/demo_threading/rust", "examples/qml_features/rust", "examples/qml_minimal/rust", + "examples/widgets_minimal", "tests/basic_cxx_only/rust", "tests/basic_cxx_qt/rust", diff --git a/crates/cxx-qt-lib-extras/src/gui/qpushbutton.rs b/crates/cxx-qt-lib-extras/src/gui/qpushbutton.rs index dda32ad9c..4f7f2d092 100644 --- a/crates/cxx-qt-lib-extras/src/gui/qpushbutton.rs +++ b/crates/cxx-qt-lib-extras/src/gui/qpushbutton.rs @@ -35,6 +35,9 @@ mod ffi { } impl ffi::QPushButton { + // TODO: we need to think about how ownership in widgets is going to work + // as for items like QPushButton you may have a parent and have that + // free the object and not when the unique ptr goes out of scope pub fn new() -> cxx::UniquePtr { ffi::qpushbutton_new() } diff --git a/examples/widgets_minimal/Cargo.toml b/examples/widgets_minimal/Cargo.toml new file mode 100644 index 000000000..fe7a6255c --- /dev/null +++ b/examples/widgets_minimal/Cargo.toml @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +# SPDX-FileContributor: Andrew Hayzen +# +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[package] +name = "widgets-minimal-no-cmake" +version = "0.1.0" +authors = [ + "Andrew Hayzen ", + "Be Wilson ", + "Gerhard de Clercq ", + "Leon Matthes " +] +edition = "2021" +license = "MIT OR Apache-2.0" + +[dependencies] +cxx.workspace = true +cxx-qt.workspace = true +cxx-qt-lib.workspace = true +cxx-qt-lib-extras.workspace = true + +[build-dependencies] +# The link_qt_object_files feature is required for statically linking Qt 6. +cxx-qt-build = { workspace = true, features = [ "link_qt_object_files" ] } +cxx-qt-lib-headers.workspace = true +cxx-qt-lib-extras-headers.workspace = true diff --git a/examples/widgets_minimal/build.rs b/examples/widgets_minimal/build.rs new file mode 100644 index 000000000..bdd5a8e50 --- /dev/null +++ b/examples/widgets_minimal/build.rs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use cxx_qt_build::CxxQtBuilder; + +fn main() { + CxxQtBuilder::new() + // Link Qt's Network library + .qt_module("Network") + .with_opts(cxx_qt_lib_headers::build_opts()) + .with_opts(cxx_qt_lib_extras_headers::build_opts()) + .build(); +} diff --git a/examples/widgets_minimal/src/main.rs b/examples/widgets_minimal/src/main.rs new file mode 100644 index 000000000..635088cbe --- /dev/null +++ b/examples/widgets_minimal/src/main.rs @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! This example provides demostrations of building a Qt Widgets CXX-Qt application + +use cxx_qt_lib::QString; +use cxx_qt_lib_extras::{QApplication, QPushButton}; + +fn main() { + let mut app = QApplication::new(); + + // TODO: we should really pass a parent in here + let mut push_button = QPushButton::new(); + + if let Some(mut push_button) = push_button.as_mut() { + push_button + .as_mut() + .set_text(&QString::from("Hello World!")); + + push_button + .as_mut() + .on_clicked(|_, _| { + println!("Button Clicked!"); + }) + .release(); + + push_button.show(); + } + + if let Some(app) = app.as_mut() { + app.exec(); + } +}