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. Convert QQuickItem* to QObject*

Convert QQuickItem* to QObject*

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.2k 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
    Adrian.Aioanei
    wrote on last edited by
    #1

    I have succeed to create some signal an qml and some slot to deal with them.
    I have created an empty project with the new application and it works, but when i add the code to an older app it say
    cannot convert 'QQuickItem*' to 'QObject*' in initialization QObject *item = view2.rootObject()

    My function look like this:

    void fromQML::loadQuestion()
    {
        view2.setSource (QUrl("qrc:/question.qml"));
        QObject *item = view2.rootObject(); //here is the error and doesn't work if i make cast
        loadProcess load;
        QObject::connect(item, SIGNAL(qmlYesSig()),&load, SLOT(forYes()));
        QObject::connect(item, SIGNAL(qmlNoSig()),&load, SLOT(forNo()));
    }
    

    It the working application the code looks like this:

        QGuiApplication app(argc, argv);
    
        QQuickView view;
        view.setSource (QUrl("qrc:/main.qml"));
        QObject *item = view.rootObject();
    
        testClass myClass;
        QObject::connect(item, SIGNAL(qmlYesSig(QString)),
                         &myClass, SLOT(cppSlot(QString)));
    
        QObject::connect(item, SIGNAL(qmlNoSig(QString)),
                         &myClass, SLOT(cppSlot(QString)));
    

    From my point of view is the same staff so i don't understand why in first sample doesn't work and is the second does.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adrian.Aioanei
      wrote on last edited by
      #2

      I have try again and if i make the connection in main it works but if i copy and paste the some code in a C++ slot it give me the above error.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        While that is surprising, why not use QQuickItem* item = view2.rootObject(); since it's what the method returns ?

        Note that your load object will be destroyed at the end of loadQuestion so it might not do anything.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

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