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. QML engine rootObjects still empty when Component.onCompleted is invoked
Forum Update on Monday, May 27th 2025

QML engine rootObjects still empty when Component.onCompleted is invoked

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 931 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.
  • T Offline
    T Offline
    Tom asso
    wrote on 11 Sept 2019, 22:25 last edited by Tom asso 9 Nov 2019, 22:27
    #1

    Why is the app engine's rootObject list still empty even when Component.onCompleted is invoked?

    I want to call a C++ singleton backend method from qml when the engine has completely loaded the qml, without any user interaction. The backend method needs to access a specific qml item, so the method takes an objectName as input parameter, then invokes rootObject->findChild(objectName) to get the item's object. The qml looks like this:

    Window {
       [...]
      Surface3D {
         Surface3DSeries {
           objectName = "myseries"
         }
      }
      // Invoke BackEnd C++ method when Window is complete
      Component.onCompleted: {
        BackEnd.foo("myseries");
      }
    }
    

    BackEnd.foo() looks like this:

    bool BackEnd::foo() {
      char *seriesName = seriesNameString.toLatin1().data();
      if (g_appEngine->rootObjects().isEmpty()) {
          // rootObjects are empty - how to find seriesName object???
          qDebug("rootObjects are empty");
          return false;
        }
        // Get root window
      QObject *root = qobject_cast<QQuickWindow*>(g_appEngine->rootObjects().value(0));
    
     QSurface3DSeries *surface3DSeries = 
           root->findChild<QSurface3DSeries *>(seriesName);
      if (!surface3DSeries) {
          qCritical() << "Couldn't find QSurface3DSeries " << seriesNameString << " object";
          return false;
        }
    

    So how can I invoke BackEnd.foo() from qml and find the object specified by objectName?

    Thanks
    Tom

    1 Reply Last reply
    0

    1/1

    11 Sept 2019, 22:25

    • Login

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