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

Behavior or QQmlEngine::clearComponentCache changed in Qt 6.8.3

    XMLWordPrintable

Details

    Description

       

      Behavior of QQmlEngine::clearComponentCache has changed in 6.8.3 in comparison to 6.8.2 and earlier versions, affecting users functionalities relying on that method and it's behavior.

       

      The following code:

      import QtQuick
      import QtQuick.Controls
      import Test
      
      Window {
          id: root
      
          visible: true
      
          function load() {
              const component = Qt.createComponent(`MyItem.qml`)
              return component.createObject(root)
          }
      
          Component.onCompleted: {
              let instance = load()
              console.log(instance)
              instance.destroy()
      
              CacheCleaner.clearComponentCache()
              instance = load()
              console.log(instance)
          }
      }
      

      On Qt 6.8.2 prints:

      qml: MyItem_QMLTYPE_2(0x7ee6a4002df0)
      qml: MyItem_QMLTYPE_3(0x5706d0db0dd0)

      The component has been removed from the cache resulting with other type name for the second instance.

      On Qt 6.8.3:

      qml: MyItem_QMLTYPE_2(0x71a958002df0)
      qml: MyItem_QMLTYPE_2(0x5cc39bb09c00)

      The type remains the same.

      To achieve similar behavior (but not exactly the same) it can be modified to e.g.:

       

      import QtQuick
      import QtQuick.Controls
      import Test
      
      Window {
          id: root
      
          visible: true
      
          function load() {
              const component = Qt.createComponent(`MyItem.qml`)
              return component.createObject(root)
          }
      
          Component.onCompleted: {
              const instance = load()
              console.log(instance)
              instance.destroy()
      
              CacheCleaner.clearComponentCache()
      
              Qt.callLater(() => {
                  CacheCleaner.clearComponentCache()
                  const instance = load()
                  console.log(instance)
              })
          }
      }
      

      However it's also not clear why two separate calls to QQmlEngine::clearComponentCache are needed to achieve desired effect of cache clearing.

       

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            michalc Michał Cieślak
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes