diff --git a/README.md b/README.md index a5303a3..cf31c15 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,12 @@ Enables `QtWebEngine` functionality. For more details see the [example](./exampl This feature is disabled by default. +### `widgets` + +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 diff --git a/qmetaobject/Cargo.toml b/qmetaobject/Cargo.toml index af30d9a..dca05c0 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", "widgets"] chrono_qdatetime = ["qttypes/chrono"] webengine = ["qttypes/qtwebengine"] +widgets = ["qttypes/qtwidgets"] [dependencies] qttypes = { path = "../qttypes", version = "0.2.0", features = ["qtquick"] } diff --git a/qmetaobject/build.rs b/qmetaobject/build.rs index cf7598f..7cad383 100644 --- a/qmetaobject/build.rs +++ b/qmetaobject/build.rs @@ -26,6 +26,11 @@ fn main() { .expect("Parsing Qt version failed"); let mut config = cpp_build::Config::new(); + + if cfg!(not(feature = "widgets")) { + config.define("NO_WIDGETS", None); + } + for f in std::env::var("DEP_QT_COMPILE_FLAGS").unwrap().split_terminator(";") { config.flag(f); } diff --git a/qmetaobject/src/qtdeclarative.rs b/qmetaobject/src/qtdeclarative.rs index 07dc491..e824650 100644 --- a/qmetaobject/src/qtdeclarative.rs +++ b/qmetaobject/src/qtdeclarative.rs @@ -28,8 +28,15 @@ cpp! {{ #include #include #include - #include #include + + #ifdef NO_WIDGETS + # define QAPPLICATION QGuiApplication + # include + #else + # define QAPPLICATION QApplication + # include + #endif struct SingleApplicationGuard { SingleApplicationGuard() { @@ -47,12 +54,12 @@ 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 QAPPLICATION(argc, argv)) , engine(new QQmlApplicationEngine()) {} }; diff --git a/qttypes/Cargo.toml b/qttypes/Cargo.toml index 1717e26..f328a77 100644 --- a/qttypes/Cargo.toml +++ b/qttypes/Cargo.toml @@ -27,13 +27,15 @@ qtquickcontrols2 = [] # Link against QtMultimedia qtmultimedia = [] # Link against QtMultimediaWidgets -qtmultimediawidgets = [] +qtmultimediawidgets = ["qtwidgets"] # Link against QtSql qtsql = [] # Link against QtTest qttest = [] +# Link against QtWidgets +qtwidgets = [] -default = ["required"] +default = ["required", "qtwidgets"] [dependencies] cpp = "0.5.6" diff --git a/qttypes/build.rs b/qttypes/build.rs index c6cda86..1ba4702 100644 --- a/qttypes/build.rs +++ b/qttypes/build.rs @@ -243,6 +243,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 ba04e85..b3dd97f 100644 --- a/qttypes/src/lib.rs +++ b/qttypes/src/lib.rs @@ -116,6 +116,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //! | **`qtsql`** | Qt SQL | //! | **`qttest`** | Qt Test | //! | **`qtwebengine`** | Qt WebEngine | +//! | **`qtwidgets`** | Qt Widgets | //! #![cfg_attr(no_qt, allow(unused))]