From 5a9225f4c6368ee79877e4245cc7ab813dd4ef29 Mon Sep 17 00:00:00 2001 From: "william.fink" Date: Thu, 17 Aug 2023 12:01:32 +0200 Subject: [PATCH 1/2] Feature "qtwidgets" added. Link with QtWidgets and use QApplication when activated (default) Use QGuiApplication when not. --- qmetaobject/Cargo.toml | 3 ++- qmetaobject/build.rs | 4 ++++ qmetaobject/src/qtdeclarative.rs | 14 +++++++++++--- qttypes/Cargo.toml | 2 ++ qttypes/build.rs | 1 + qttypes/src/lib.rs | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/qmetaobject/Cargo.toml b/qmetaobject/Cargo.toml index 48b16caa..6cbd26bd 100644 --- a/qmetaobject/Cargo.toml +++ b/qmetaobject/Cargo.toml @@ -12,9 +12,10 @@ keywords = ["Qt", "QML", "QMetaObject",] repository = "https://github.com/woboq/qmetaobject-rs" [features] -default = ["log"] +default = ["log", "qtwidgets"] chrono_qdatetime = ["qttypes/chrono"] webengine = ["qttypes/qtwebengine"] +qtwidgets = ["qttypes/qtwidgets"] [dependencies] qttypes = { path = "../qttypes", version = "0.2.0", features = ["qtquick"] } diff --git a/qmetaobject/build.rs b/qmetaobject/build.rs index cf7598fa..3ef8b485 100644 --- a/qmetaobject/build.rs +++ b/qmetaobject/build.rs @@ -29,6 +29,10 @@ fn main() { for f in std::env::var("DEP_QT_COMPILE_FLAGS").unwrap().split_terminator(";") { config.flag(f); } + + #[cfg(feature = "qtwidgets")] + config.define("USE_QTWIDGETS", None); + config.include(&qt_include_path).build("src/lib.rs"); for minor in 7..=15 { diff --git a/qmetaobject/src/qtdeclarative.rs b/qmetaobject/src/qtdeclarative.rs index 5c771580..69d0ff38 100644 --- a/qmetaobject/src/qtdeclarative.rs +++ b/qmetaobject/src/qtdeclarative.rs @@ -28,9 +28,16 @@ cpp! {{ #include #include #include - #include #include +#if USE_QTWIDGETS + #include + using QmlAppType = QApplication; +#else + #include + using QmlAppType = QGuiApplication; +#endif + struct SingleApplicationGuard { SingleApplicationGuard() { rust!(Rust_QmlEngineHolder_ctor[] { @@ -47,12 +54,13 @@ cpp! {{ }; struct QmlEngineHolder : SingleApplicationGuard { - std::unique_ptr app; + std::unique_ptr app; + std::unique_ptr engine; std::unique_ptr view; QmlEngineHolder(int &argc, char **argv) - : app(new QApplication(argc, argv)) + : app(new QmlAppType(argc, argv)) , engine(new QQmlApplicationEngine()) {} }; diff --git a/qttypes/Cargo.toml b/qttypes/Cargo.toml index 9df14bd9..2a96ed61 100644 --- a/qttypes/Cargo.toml +++ b/qttypes/Cargo.toml @@ -20,6 +20,8 @@ required = [] # Link against QtQuick qtquick = [] +# Link against QtWidgets +qtwidgets = [] # Link against QtWebEngine qtwebengine = [] # Link against QtQuickControls2 diff --git a/qttypes/build.rs b/qttypes/build.rs index a6856ad6..fcca044d 100644 --- a/qttypes/build.rs +++ b/qttypes/build.rs @@ -228,6 +228,7 @@ fn main() { }; link_lib("Core"); link_lib("Gui"); + #[cfg(feature = "qtwidgets")] link_lib("Widgets"); #[cfg(feature = "qtquick")] link_lib("Quick"); diff --git a/qttypes/src/lib.rs b/qttypes/src/lib.rs index 00e2bc43..01412e47 100644 --- a/qttypes/src/lib.rs +++ b/qttypes/src/lib.rs @@ -112,6 +112,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //! | **`qtmultimedia`** | Qt Multimedia | //! | **`qtmultimediawidgets`** | Qt Multimedia Widgets | //! | **`qtquick`** | Qt Quick | +//! | **`qtwidgets`** | Qt Widgets | //! | **`qtquickcontrols2`** | Qt Quick Controls | //! | **`qtsql`** | Qt SQL | //! | **`qttest`** | Qt Test | From b5d7dc023ae01074c54702738e3d25456e6b4a63 Mon Sep 17 00:00:00 2001 From: "william.fink" Date: Fri, 18 Aug 2023 15:57:29 +0200 Subject: [PATCH 2/2] Feature "qtwidgets" added to README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 3a53bd81..45203656 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,13 @@ Enables `QtWebEngine` functionality. For more details see the [example](./exampl This feature is disabled by default. +### `qtwidgets` + +Link against `QtWidgets` module. This will use `QApplication` instead of `QGuiApplication`. + +This feature is enabled by default. + + ## What if a wrapper for the Qt C++ API is missing? It is quite likely that you would like to call a particular Qt function which