Load status of asynchronously started component



  • We're using QML to implement plugins to an application written in C++ .
    This means allowing for the possibility of users supplying broken code. To avoid broken scripts crashing the app I'm loading the script into a component asynchronously. This works nicely when I run it under the (QtCreator) debugger. Otherwise it doesn't load scripts at all!

    The code I'm using is

    @ QQmlComponent component(engine, QUrl::fromLocalFile(d->path), QQmlComponent::Asynchronous);
    qDebug("Collect meta for <%s>", qPrintable(d->path));
    QThread::yieldCurrentThread();

      int loadDelay = 20;
      while( !component.isReady() && loadDelay--) {
            cProgress = component.progress();
            qDebug("Component loading progress %f%%", cProgress);
            if(cProgress == 1.0 || component.isError())
                  break;
            sleep(1);
            }
    
      if(component.isReady()) {
             &tc
    

    @

    When I run this under the debugger, by line 6 the component has a status of "Ready" and progress is 1.0, it also correctly identifies the first script failure, if there is one. Otherwise, for the whole delay loop, the status stays at "Loading", the progress counter stays at zero, and the load fails, for clean or broken scripts.
    I've put the thread yield in there hoping that that would resolve the issue, but it doesn't.

    Can someone help me out here?
    Going asynchronous was marvellous in preventing the crash, but...



  • Interestingly (?), when running this through the debugger if I pause execution by putting a breakpoint ON line 1 above and then single step through it, the call still fails. If I stop it before that line and single step through it, it works. What does that mean?

    I've now tried loading the script separately, with loadUrl, after instantiating the component object, that doesn't work either.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.