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. Correct way to quit application. How?
QtWS25 Last Chance

Correct way to quit application. How?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 590 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by bogong
    #1

    Hello all!

    I've got issue with destroying objects in application at time of exit. A have kind of backend object that is outside of QQmlApplicationEngine. When I am exiting application I've got this error in QML:

    qrc:/Mobile/qml/Main/Mobile.qml:67: TypeError: Cannot call method 'SomeMethod' of null
    

    I understand that object that is called from QML destroying first. How to make be destroyed after destroying QQmlApplicationEngine? Is there any signal in QQmlApplicationEngine that is showing "died"? I found only signal quit().

    Or should I be catching quit event somehow and destroy it manually?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Simply parent your backend to the engine. Then it will get cleaned up correctly and at the right moment.

      Something like (pseudo code):

      QQmlApplicationEngine engine;
      Backend *backend = new Backend(&engine);
      

      (Z(:^

      B 3 Replies Last reply
      0
      • sierdzioS sierdzio

        Simply parent your backend to the engine. Then it will get cleaned up correctly and at the right moment.

        Something like (pseudo code):

        QQmlApplicationEngine engine;
        Backend *backend = new Backend(&engine);
        
        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        @sierdzio thx will try tomorrow.

        1 Reply Last reply
        0
        • sierdzioS sierdzio

          Simply parent your backend to the engine. Then it will get cleaned up correctly and at the right moment.

          Something like (pseudo code):

          QQmlApplicationEngine engine;
          Backend *backend = new Backend(&engine);
          
          B Offline
          B Offline
          bogong
          wrote on last edited by
          #4

          @sierdzio I do something missing. Still have this troubles. My backend is Singletone. Can it be source of the problem?

          1 Reply Last reply
          0
          • sierdzioS sierdzio

            Simply parent your backend to the engine. Then it will get cleaned up correctly and at the right moment.

            Something like (pseudo code):

            QQmlApplicationEngine engine;
            Backend *backend = new Backend(&engine);
            
            B Offline
            B Offline
            bogong
            wrote on last edited by
            #5

            @sierdzio Issue solved. Thx for assistance. The problem was happening because I've been starting QQmlEngine inside of another object, not in main. When all of it started in main and backend is after engine - all is working perfectly.

            Something like this:

            int main(int inCounter, char *inArguments[]) {
            
            	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
            	QGuiApplication oApplication(inCounter, inArguments);
            	QQmlApplicationEngine oEngine;
            
            	Backend* oBackend = &Backend::mInstance(
            		&oApplication,&oEngine,oEngine.rootContext()
            	);
            	oBackend->mInit();
            
            	const QUrl oURL(QStringLiteral(MOBILE_QML_MAIN));
            	QObject::connect(
            		&oEngine, &QQmlApplicationEngine::objectCreated,
            		&oApplication, [oURL](QObject *obj, const QUrl &objUrl) {
            			if (!obj && oURL == objUrl) {
            				QCoreApplication::exit(-1);
            			}
            		}, Qt::QueuedConnection
            	);
            	oEngine.load(oURL);
            
            	return oApplication.exec();
            }
            

            I've tried to put it inside of wrapper together with backend where all of them has one parent. Got failed. When both of them in main - all is OK.

            1 Reply Last reply
            2

            • Login

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