Skip to content
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

Feature "qtwidgets" added. #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion qmetaobject/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 4 additions & 0 deletions qmetaobject/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions qmetaobject/src/qtdeclarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ cpp! {{
#include <memory>
#include <QtQuick/QtQuick>
#include <QtCore/QDebug>
#include <QtWidgets/QApplication>
#include <QtQml/QQmlComponent>

#if USE_QTWIDGETS
#include <QtWidgets/QApplication>
using QmlAppType = QApplication;
#else
#include <QtGui/QGuiApplication>
using QmlAppType = QGuiApplication;
#endif

struct SingleApplicationGuard {
SingleApplicationGuard() {
rust!(Rust_QmlEngineHolder_ctor[] {
Expand All @@ -47,12 +54,13 @@ cpp! {{
};

struct QmlEngineHolder : SingleApplicationGuard {
std::unique_ptr<QApplication> app;
std::unique_ptr<QmlAppType> app;

std::unique_ptr<QQmlApplicationEngine> engine;
std::unique_ptr<QQuickView> view;

QmlEngineHolder(int &argc, char **argv)
: app(new QApplication(argc, argv))
: app(new QmlAppType(argc, argv))
, engine(new QQmlApplicationEngine())
{}
};
Expand Down
2 changes: 2 additions & 0 deletions qttypes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ required = []

# Link against QtQuick
qtquick = []
# Link against QtWidgets
qtwidgets = []
# Link against QtWebEngine
qtwebengine = []
# Link against QtQuickControls2
Expand Down
1 change: 1 addition & 0 deletions qttypes/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn main() {
};
link_lib("Core");
link_lib("Gui");
#[cfg(feature = "qtwidgets")]
link_lib("Widgets");
#[cfg(feature = "qtquick")]
link_lib("Quick");
Expand Down
1 change: 1 addition & 0 deletions qttypes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down