Integrating QML and C++
-
I create a program in qt creator "Qt widget application" for raspberry pi (cross-compiling). I need to put a QML object in the program and have access to its property (color, height, width, etc.)
Placing qml objects works like this:QQuickWidget * view = new QQuickWidget (ui-> centralWidget); view-> SetSource (QUrl :: fromLocalFile ( "main.qml")); view-> show ();
Unfortunately, here I have no way to change the properties QML in runtime.
How to do it is described here:
https://doc-snapshots.qt.io/qt5-5.9/qtqml-cppintegration-interactqmlfromcpp.htmlbut I have a problem with embedding this QML object on the form of my application.
I do it this way:QQuickView * view = new QQuickView (); QWidget * container = QWidget :: createWindowContainer (view, this); container-> setMinimumSize (200.400); container-> setMaximumSize (200.400); container-> setFocusPolicy (Qt :: TabFocus); view-> SetSource (QUrl ( "main.qml")); layout-> addWidget (container);
Here, unfortunately, I have an error: EGLFS: "OpenGL windows can not be mixed with others."
I'm stuck. I tried dozens of ways. How do I set up a QML object in my application that I can change RUNTIME?
-
@pirates21 said in Integrating QML and C++:
Placing qml objects works like this:
QQuickWidget * view = new QQuickWidget (ui-> centralWidget);
view-> SetSource (QUrl :: fromLocalFile ( "main.qml"));
view-> show ();Unfortunately, here I have no way to change the properties QML in runtime.
why not?
view->rootObject()
gives you the QuickItem* for the item specified in main.qmlqreal height = QQmlProperty(view->rootObject(), "height").read().value<qreal>(); // or qreal height = view->rootObject()->property("height").value<qreal>();