Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Add QML objects to your C++ widget application.

Add QML objects to your C++ widget application.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 3.7k Views
  • 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.
  • B Offline
    B Offline
    bask185
    wrote on 13 Jul 2017, 07:34 last edited by
    #1

    My company's High Command has ordered me to develop a tumbler.

    This tumbler or rrrrrrrr-thing as we call it is a QML type object. And I have no experience with QML. I have already googled some stuff but I can't find how to add a QML object to the rest of my application.

    I do know:

    • I have to use a QGraphicView widget. I already have one of those in use with some extra space left. (I'm using Qt 5.8)
    • I must include: #include <QtQuick/QQuickView> and #include <QtQml/QQmlEngine> in the header file
    • I must make a new QML file.

    What I don't know:

    • how can I make a QML object in my cpp file and give it a place on my QGraphicView?
    1 Reply Last reply
    0
    • B Offline
      B Offline
      bask185
      wrote on 13 Jul 2017, 12:33 last edited by
      #5

      Ok that solved the error problems. I don't think I will forget this a 3rd time @jsulm ;)

      I also ditched the code I had and I moved the QML file to the resource folder. Using Qt creator's convenient style sheet bar thing (that bar in the UI on the right with all the parameters) I selected the QML file and I got me a working Tumbler \o/

      I am only far removed from the part in which this tumbler is going to be but... minor detail

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 13 Jul 2017, 07:41 last edited by
        #2

        http://doc.qt.io/qt-5/qquickwidget.html

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • B Offline
          B Offline
          bask185
          wrote on 13 Jul 2017, 08:19 last edited by bask185
          #3

          Hm so far for the need of a QGraphicView :)

          I have done:

          • added to header.
          #include <QtQuickWidgets/QQuickWidget>
          
          • added to header
          QQuickWidget *view;
          
          
          • added to setup of CPP file
          view = new QQuickWidget;
          view->setSource(QUrl::fromLocalFile("Tumbler.qml"));
          view->show();
          

          But I'm having error messages

          mainwindow.cpp:-1: error: undefined reference to `QQuickWidget::QQuickWidget(QWidget*)'
          mainwindow.cpp:-1: error: undefined reference to `QQuickWidget::setSource(QUrl const&)'
          mainwindow.cpp:-1: error: undefined reference to `QQuickWidget::QQuickWidget(QWidget*)'
          mainwindow.cpp:-1: error: undefined reference to QQuickWidget::setResizeMode(QQuickWidget::ResizeMode)'
          :-1: error: collect2: error: ld returned 1 exit status
          

          Did I include the wrong library or something????

          BTW: I also added a QQuickWidget to the ui which is named 'view'

          J 1 Reply Last reply 13 Jul 2017, 11:34
          0
          • B bask185
            13 Jul 2017, 08:19

            Hm so far for the need of a QGraphicView :)

            I have done:

            • added to header.
            #include <QtQuickWidgets/QQuickWidget>
            
            • added to header
            QQuickWidget *view;
            
            
            • added to setup of CPP file
            view = new QQuickWidget;
            view->setSource(QUrl::fromLocalFile("Tumbler.qml"));
            view->show();
            

            But I'm having error messages

            mainwindow.cpp:-1: error: undefined reference to `QQuickWidget::QQuickWidget(QWidget*)'
            mainwindow.cpp:-1: error: undefined reference to `QQuickWidget::setSource(QUrl const&)'
            mainwindow.cpp:-1: error: undefined reference to `QQuickWidget::QQuickWidget(QWidget*)'
            mainwindow.cpp:-1: error: undefined reference to QQuickWidget::setResizeMode(QQuickWidget::ResizeMode)'
            :-1: error: collect2: error: ld returned 1 exit status
            

            Did I include the wrong library or something????

            BTW: I also added a QQuickWidget to the ui which is named 'view'

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 13 Jul 2017, 11:34 last edited by
            #4

            @bask185 said in Add QML objects to your C++ widget application.:

            QQuickWidget

            Did you add

            QT += quickwidgets
            

            to your pro file as is stated here http://doc.qt.io/qt-5/qquickwidget.html ?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            5
            • B Offline
              B Offline
              bask185
              wrote on 13 Jul 2017, 12:33 last edited by
              #5

              Ok that solved the error problems. I don't think I will forget this a 3rd time @jsulm ;)

              I also ditched the code I had and I moved the QML file to the resource folder. Using Qt creator's convenient style sheet bar thing (that bar in the UI on the right with all the parameters) I selected the QML file and I got me a working Tumbler \o/

              I am only far removed from the part in which this tumbler is going to be but... minor detail

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Groovy
                wrote on 23 Mar 2020, 11:43 last edited by Groovy
                #6

                i still don't get it how did you add the qml to the graphic view .ui

                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