Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Integrating QML and C++
Forum Updated to NodeBB v4.3 + New Features

Integrating QML and C++

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 598 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pirates21
    wrote on last edited by pirates21
    #1

    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.html

    but 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?

    raven-worxR 1 Reply Last reply
    0
    • P pirates21

      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.html

      but 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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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.qml

      qreal height = QQmlProperty(view->rootObject(), "height").read().value<qreal>();
      // or
      qreal height = view->rootObject()->property("height").value<qreal>();
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • P Offline
        P Offline
        pirates21
        wrote on last edited by
        #3

        It works. Thank you very much! :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved