QML engine rootObjects still empty when Component.onCompleted is invoked
Unsolved
QML and Qt Quick
-
wrote on 11 Sept 2019, 22:25 last edited by Tom asso 9 Nov 2019, 22:27
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/1