Get the root object from QML

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

    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    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?.


  • Moderators

    • 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 ;)

  • Hi,

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

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.