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. Get the root object from QML
Qt 6.11 is out! See what's new in the release blog

Get the root object from QML

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.2k 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.
  • K Offline
    K Offline
    karim24
    wrote on last edited by
    #1

    I have a QML project with the following code in main.cpp

    @
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
    @

    How do I get the rootObject so I can access the QML elements to do C++ bindings, all the examples that I have seen , they load the QML with QQuickView, so is it possible to get the root object from QQmlApplicationEngine?.

    Thanks

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2
      • QQmlApplicationEngine::​rootObjects()
      • QQuickView::rootObject()

      i bet the time writing this post took longer than it would have to check the docs for what you want ;)

      --- 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
      0
      • Pradeep P NP Offline
        Pradeep P NP Offline
        Pradeep P N
        wrote on last edited by
        #3

        Hi,

        use engine.rootObject() method to get the list of objects.

        Pradeep Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        1 Reply Last reply
        2
        • K Offline
          K Offline
          karim24
          wrote on last edited by
          #4

          You gotta be kidding me, that's all I wasted hours trying to do that, I checked the documentation and "googled" it, I have no idea how I missed that.

          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