Chain of loading objects. How?
-
Hello!
I've got issue to release the chain of objects one-after-another in main process. It's mean next objects is starting creating only after finished previous. I understand that this issue might be solved by signal-slot functionality. I am OK with object-to-object interaction, but how to do it correctly in case of QML application in the main process?
For example I need start creating Object2 only after finishing all of creating functions in Object1 (it's not only constructor) and other:
int main(int inCounter, char *inArguments[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication oApplication(inCounter,inArguments); QQmlApplicationEngine oEngine; aObject1* oObject1 = new aObject1(); aObject2* oObject2 = new aObject2(); aObject3* oObject3 = new aObject3(); const QUrl oUrl(QStringLiteral("qrc:/main.qml")); QObject::connect( &oEngine, &QQmlApplicationEngine::objectCreated, &oApplication, [oUrl](QObject *oObj, const QUrl &oObjUrl) { if (!oObj && oUrl == oObjUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection ); oEngine.load(oUrl); return oApplication.exec(); }
-
-
@VRonin Thanks for reply:
- What are those "creating functions" are they multithread? is it an asynchronous process? - Yes, they might be multithread.
- How do you know if they finished or not? - I've been thinking about signal that might be caught somehow.
-
Hi,
Can you explain a bit what makes these object delayed in their creation ?
There could be several solutions to solve that issue.
-
@VRonin Just published examples of what I've been asking. There are to application loading scenarios released by two scenarios: one in loader object and another one in main function. But both of them has unresolved issue - the application continue running but should be waiting while last one required object will done.
In details it's mean that this part of main function of application should be running only after last object loaded properly:
if (oLoader) { aLOG << oObject1->mTestString(); aLOG << oObject2->mTestString(); aLOG << oObject3->mTestString(); }
How to implement it?
-
One way could be to have a controller object to which you pass a vector of your objects to initialise. Have a lambda connected to it that will finish the loading of whatever is needed after the initialisation is done.