Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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();
    }
    


  • @bogong said in Chain of loading objects. How?:

    all of creating functions in Object1 (it's not only constructor)

    What are those "creating functions" are they multithread? is it an asynchronous process? how do you know if they finished or not?



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

  • Lifetime Qt Champion

    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?



  • Published example of finished loading process in one thread.


  • Lifetime Qt Champion

    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.



  • Issue closed. All done by my own. This examples demonstrating 3 version of releasing chained steps of application loading process independently of which type the object is or using threads.


Log in to reply