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. Cannot execute examples from Doc

Cannot execute examples from Doc

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 4 Posters 498 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.
  • A Offline
    A Offline
    AlainBo
    wrote on last edited by
    #1

    Hello,

    I'm trying to learn about connections between QML and C++ and I don't understand why I cannot get the examples from doc working.

    For example, I try to use this simple example.

    So my full main.cpp code is:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQuickView>
    
    class MyClass : public QObject
    {
        Q_OBJECT
    public slots:
        void cppSlot(const QString &msg) {
            qDebug() << "Called the C++ slot with message:" << msg;
        }
    };
    
    int main(int argc, char *argv[]) {
        QGuiApplication app(argc, argv);
    
        QQuickView view(QUrl::fromLocalFile("MyItem.qml"));
        QObject *item = view.rootObject();
    
        MyClass myClass;
        QObject::connect(item, SIGNAL(qmlSignal(QString)),
                         &myClass, SLOT(cppSlot(QString)));
    
        view.show();
        return app.exec();
    }
    
    

    And when I try to build it, I get the following errors:

    main.cpp:18: error: cannot initialize a variable of type 'QObject *' with an rvalue of type 'QQuickItem *'
    main.cpp:-1: In function 'int qMain(int, char**)':
    main.cpp:18: error: cannot convert 'QQuickItem*' to 'QObject*' in initialization
         QObject *item = view.rootObject();
                                         ^
    D:\Qt\5.12.6\mingw73_64\include\QtQuick\qquickview.h:43: In file included from D:\Qt\5.12.6\mingw73_64\include\QtQuick/qquickview.h:43:0,
    D:\Qt\5.12.6\mingw73_64\include\QtQuick\QQuickView:1: from D:\Qt\5.12.6\mingw73_64\include\QtQuick/QQuickView:1,
    main.cpp:3: from ..\test2\main.cpp:3:
    D:\Qt\5.12.6\mingw73_64\include\QtQuick\qquickwindow.h:55: class type 'QQuickItem' is incomplete
     class QQuickItem;
           ^~~~~~~~~~
    

    How to solve it and why is it so complex to use examples?

    Regards

    aha_1980A ODБOïO 2 Replies Last reply
    0
    • A AlainBo

      Hello,

      I'm trying to learn about connections between QML and C++ and I don't understand why I cannot get the examples from doc working.

      For example, I try to use this simple example.

      So my full main.cpp code is:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QQuickView>
      
      class MyClass : public QObject
      {
          Q_OBJECT
      public slots:
          void cppSlot(const QString &msg) {
              qDebug() << "Called the C++ slot with message:" << msg;
          }
      };
      
      int main(int argc, char *argv[]) {
          QGuiApplication app(argc, argv);
      
          QQuickView view(QUrl::fromLocalFile("MyItem.qml"));
          QObject *item = view.rootObject();
      
          MyClass myClass;
          QObject::connect(item, SIGNAL(qmlSignal(QString)),
                           &myClass, SLOT(cppSlot(QString)));
      
          view.show();
          return app.exec();
      }
      
      

      And when I try to build it, I get the following errors:

      main.cpp:18: error: cannot initialize a variable of type 'QObject *' with an rvalue of type 'QQuickItem *'
      main.cpp:-1: In function 'int qMain(int, char**)':
      main.cpp:18: error: cannot convert 'QQuickItem*' to 'QObject*' in initialization
           QObject *item = view.rootObject();
                                           ^
      D:\Qt\5.12.6\mingw73_64\include\QtQuick\qquickview.h:43: In file included from D:\Qt\5.12.6\mingw73_64\include\QtQuick/qquickview.h:43:0,
      D:\Qt\5.12.6\mingw73_64\include\QtQuick\QQuickView:1: from D:\Qt\5.12.6\mingw73_64\include\QtQuick/QQuickView:1,
      main.cpp:3: from ..\test2\main.cpp:3:
      D:\Qt\5.12.6\mingw73_64\include\QtQuick\qquickwindow.h:55: class type 'QQuickItem' is incomplete
       class QQuickItem;
             ^~~~~~~~~~
      

      How to solve it and why is it so complex to use examples?

      Regards

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @AlainBo

      please show your project .pro file.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • A AlainBo

        Hello,

        I'm trying to learn about connections between QML and C++ and I don't understand why I cannot get the examples from doc working.

        For example, I try to use this simple example.

        So my full main.cpp code is:

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QQuickView>
        
        class MyClass : public QObject
        {
            Q_OBJECT
        public slots:
            void cppSlot(const QString &msg) {
                qDebug() << "Called the C++ slot with message:" << msg;
            }
        };
        
        int main(int argc, char *argv[]) {
            QGuiApplication app(argc, argv);
        
            QQuickView view(QUrl::fromLocalFile("MyItem.qml"));
            QObject *item = view.rootObject();
        
            MyClass myClass;
            QObject::connect(item, SIGNAL(qmlSignal(QString)),
                             &myClass, SLOT(cppSlot(QString)));
        
            view.show();
            return app.exec();
        }
        
        

        And when I try to build it, I get the following errors:

        main.cpp:18: error: cannot initialize a variable of type 'QObject *' with an rvalue of type 'QQuickItem *'
        main.cpp:-1: In function 'int qMain(int, char**)':
        main.cpp:18: error: cannot convert 'QQuickItem*' to 'QObject*' in initialization
             QObject *item = view.rootObject();
                                             ^
        D:\Qt\5.12.6\mingw73_64\include\QtQuick\qquickview.h:43: In file included from D:\Qt\5.12.6\mingw73_64\include\QtQuick/qquickview.h:43:0,
        D:\Qt\5.12.6\mingw73_64\include\QtQuick\QQuickView:1: from D:\Qt\5.12.6\mingw73_64\include\QtQuick/QQuickView:1,
        main.cpp:3: from ..\test2\main.cpp:3:
        D:\Qt\5.12.6\mingw73_64\include\QtQuick\qquickwindow.h:55: class type 'QQuickItem' is incomplete
         class QQuickItem;
               ^~~~~~~~~~
        

        How to solve it and why is it so complex to use examples?

        Regards

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @AlainBo said in Cannot execute examples from Doc:

        'QQuickItem' is incomplete

        include QQuickItem

        N 1 Reply Last reply
        3
        • ODБOïO ODБOï

          @AlainBo said in Cannot execute examples from Doc:

          'QQuickItem' is incomplete

          include QQuickItem

          N Offline
          N Offline
          Nando
          wrote on last edited by
          #4

          @LeLev That fixes it, thank you.
          The creator should set this thread as resolved....

          1 Reply Last reply
          1

          • Login

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