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. Wait for loading object before load URL in QML application. How?
Forum Updated to NodeBB v4.3 + New Features

Wait for loading object before load URL in QML application. How?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 398 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 4 May 2021, 15:07 last edited by bogong 5 Apr 2021, 15:12
    #1

    Hello all!
    I have the backend object that is requiring some time before first QML loading in QML Engine. How to run loading QML only after backend object is loaded? This backend registering in root-context some properties, and because it's appearing faster then backend i see this kind of error:

    ReferenceError: BackendObject is not defined
    

    I understand about slot-signal. I have in backend object kind of "finished" signal. To what slot it should be connected in Engine?

    I've tried to connect something like this:

    QGuiApplication oApplication(inCounter, inArguments);
    QQmlApplicationEngine oEngine;
    
    const QUrl oURL(QStringLiteral(QML_MAIN));
    
    Backend* oBackend = &Backend::mInstance();
    oEngine.rootContext()->setContextProperty("Backend",oBackend);
    oBackend->mInit(&oApplication,&oEngine,oEngine.rootContext());
    
    QObject::connect(
    	oBackend,&SBackend::sgInitiated,
    	[&oEngine,&oURL](){
    		oEngine.load(oURL);
    	}
    );
    
    return oApplication.exec();
    

    What am I missing?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bogong
      wrote on 4 May 2021, 16:56 last edited by bogong 5 Apr 2021, 16:56
      #2

      Issue closed. Solution found - using QEventLoop before loading URL.
      Something like this:

      QGuiApplication oApplication(inCounter, inArguments);
      QQmlApplicationEngine oEngine;
      
      const QUrl oURL(QStringLiteral(QML_MAIN));
      
      QEventLoop oEventLoop;
      Backend* oBackend = &Backend::mInstance();
      oEngine.rootContext()->setContextProperty("Backend",oBackend);
      QObject::connect(
      	oBackend,&SBackend::sgInitiated,
      	&oEventLoop,&QEventLoop::quit
      );
      oBackend->mInit(&oApplication,&oEngine,oEngine.rootContext());
      oEventLoop.exec();
      
      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();
      
      1 Reply Last reply
      0

      1/2

      4 May 2021, 15:07

      • Login

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