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

Provide method to remove a single entry from QML Type Cache

    XMLWordPrintable

Details

    • All

    Description

      QQmlEngine provides 2 functions for managing in-memory cache:

      • clearComponentCache() - remove all cache entries
      • trimComponentCache() - remove unused entries (of which no instance exists)

      Request:
      Add a function to remove a single file from the cache. As a result a newly created instance from this QML file should contain changes to that file. Example: feature for resetting source property of Loader, after the source file was changed.

      Example:

      Loader {
        id: loader
        source: "FileThatChanges.qml"
      }
      
      // click button after making changes to the QML file "FileThatChanges.qml" or another file that is included by "FileThatChanges.qml"
      Button {
        text: "Reload"
        onClicked: {
          var src = loader.source
          loader.source = ""
          qmlEngine.removeFromComponentCache(src) // a C++ interface for this would be enough
          loader.soruce = src
        }
      }
      

      This can be done right now with the TypeCache property in QQmlTypeLoader, but it is private. So adding an accessor for m_typeCache in qqmltypeloader_p.h or a function like removeFromComponentCache(QString fileName) would be enough.

      Use case:
      Allow changes to QML files at runtime without clearing the whole cache. trimComponentCache() cannot always be used for this, because QML cache entries can reference one another, thus it won't clear entries referenced from other entries of which instances still exist (even if the sub-QML instance itself is deleted!).

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-81116
          # Subject Branch Project Status CR V

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              Chrisu Christian Bartsch
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change