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. Problem interacting with qml object from c++, qt5
Forum Updated to NodeBB v4.3 + New Features

Problem interacting with qml object from c++, qt5

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 6.5k 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.
  • T Offline
    T Offline
    Thunderwitch
    wrote on last edited by
    #1

    @// Using QQuickView
    QQuickView view;
    view.setSource(QUrl::fromLocalFile("MyItem.qml"));
    view.show();
    QObject object = view.rootObject();
    @
    i'm copypasting this code from ("doc":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html
    but it's not working, QTCreator print error: "cannot convert 'QQuickItem
    ' to 'QObject*' in initialization"
    Why?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @
      QQuickItem *object = view.rootObject();
      @

      Should work. Or casting. Or some other trick. QQuickItem is a kid of QObject anyway, so all ::findChildren<>() and ::metaObject() magic still works.

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bjoe
        wrote on last edited by
        #3

        Hi,

        today I had the same problem.

        gcc Error: “cannot convert ‘QQuickItem*’ to ‘QObject*’ in initialization”
        clang error: "cannot convert argument of incomplete type 'QQuickItem *' to 'QObject *'"

        Ah, incomplete type ... I love clang :-)

        Add:
        @#include<QQuickItem>@

        Then it works fine for me.

        1 Reply Last reply
        1
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Yeah, clang rocks big time :) And now it fully supports C++11, too.

          (Z(:^

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qt_erik
            wrote on last edited by
            #5

            Thanks, Bjoe, including QQuickItem worked for me too!

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qt_erik
              wrote on last edited by
              #6

              Thanks, Bjoe, including QQuickItem worked for me too!

              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