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. Deleting object after QQmlEngine quit. How?
Forum Updated to NodeBB v4.3 + New Features

Deleting object after QQmlEngine quit. How?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 481 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
    #1

    Hello all!
    I have an issue with application quit process.
    The object ABackend that is created like this:

    int main(int inCounter, char* inArguments[]) {
    
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
    	QGuiApplication oApplication(inCounter, inArguments);
    	QQmlApplicationEngine oEngine;
    
    	qInstallMessageHandler(fLoggerMessageHandler);
    
    	ABackend* oBackend = &ABackend::mInstance();
    
    	oBackend->pGuiApplication = &oApplication;
    	oBackend->pEngine = &oEngine;
    	oBackend->pRootContext = oEngine.rootContext();
    
    	oBackend->mInit();
    
    	const QUrl oURL(QStringLiteral(SCOUT_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();
    

    is deleting faster than QML engine quit properly. And result of it I see this message:

    TypeError: Cannot call method 'mSomeMethodOfAbackend' of null
    

    The question is how to delete it only after QML Engine destruction?

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

      Either move this line:

      ABackend* oBackend = &ABackend::mInstance();
      

      Before this:

      QQmlApplicationEngine oEngine;
      

      Or (better) parent oBackend under oEngine. You'll need to expose it's constructor, then do it like so:

      auto oBackend = new ABackend(&oEngine);
      

      (Z(:^

      B 1 Reply Last reply
      4
      • sierdzioS sierdzio

        Either move this line:

        ABackend* oBackend = &ABackend::mInstance();
        

        Before this:

        QQmlApplicationEngine oEngine;
        

        Or (better) parent oBackend under oEngine. You'll need to expose it's constructor, then do it like so:

        auto oBackend = new ABackend(&oEngine);
        
        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        @sierdzio Just it? I though there would be something very complicated related to Signal-Slots ... I am definitely in need of getting rest ... Started forgetting how objets parenting in Qt. Thx. Issue closed.

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

          Yeah, this started appearing a few versions ago, around 5.13 or 5.14. I think some bug fix must have changed QQmlEngine destructor or something. In every case I noticed these TypeError logs, it was enough to change parenting or initialization order to fix the issue.

          (Z(:^

          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