Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Chain of loading objects. How?
Forum Updated to NodeBB v4.3 + New Features

Chain of loading objects. How?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 610 Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by bogong
    #1

    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();
    }
    
    VRoninV 1 Reply Last reply
    0
    • B bogong

      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();
      }
      
      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @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?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      B 2 Replies Last reply
      0
      • VRoninV VRonin

        @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?

        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        @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.
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Can you explain a bit what makes these object delayed in their creation ?

          There could be several solutions to solve that issue.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • VRoninV VRonin

            @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?

            B Offline
            B Offline
            bogong
            wrote on last edited by
            #5

            @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?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bogong
              wrote on last edited by
              #6

              Published example of finished loading process in one thread.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bogong
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

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