Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-62601

Add QQmlApplicationEngine::clear() to delete root objects after clearComponentCache() is called

XMLWordPrintable

      http://doc.qt.io/qt-5/qqmlengine.html#clearComponentCache can be used to clear any loaded components, but it doesn't take care of deleting the instances of those components. If a user wants to reload the QML in their application after calling clearComponentCache(), it is not currently clear how they would do it. Apparently, deleting the root objects is enough for this, as QQmlApplicationEngine listens to the destroyed signal:

      void QQmlApplicationEnginePrivate::finishLoad(QQmlComponent *c)
      {
          Q_Q(QQmlApplicationEngine);
          switch (c->status()) {
          case QQmlComponent::Error:
              qWarning() << "QQmlApplicationEngine failed to load component";
              qWarning() << qPrintable(c->errorString());
              q->objectCreated(0, c->url());
              break;
          case QQmlComponent::Ready: {
              auto newObj = c->create();
              objects << newObj;
              QObject::connect(newObj, &QObject::destroyed, q, [&](QObject *obj) { objects.removeAll(obj); });
              q->objectCreated(objects.constLast(), c->url());
              }
              break;
          case QQmlComponent::Loading:
          case QQmlComponent::Null:
              return; //These cases just wait for the next status update
          }   
      

      A QQmlApplicationEngine::clear() function would make it obvious how to achieve this.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mitch_curtis Mitch Curtis
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes