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. Load status of asynchronously started component
Forum Updated to NodeBB v4.3 + New Features

Load status of asynchronously started component

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 650 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.
  • M Offline
    M Offline
    MarkRS
    wrote on last edited by
    #1

    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...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MarkRS
      wrote on last edited by
      #2

      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.

      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