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

Crash when QQuickView loads QML document that binds Overlay.overlay.[property]

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 6.5.5-1, 6.6.3, 6.8.0 FF
    • 6.5.4, 6.6.2, 6.7.0 Beta3
    • Quick: Controls 2
    • None
    • Windows 10 22H2, MSVC 2019 x64
    • bad5a7ac1 (dev), 56de91bec (6.7), a57e772ea (6.6), a74a8b828 (tqtc/lts-6.5)

    Description

      Code
      Adapted from https://doc.qt.io/qt-6/qml-qtquick-controls-popup.html#popup-sizing

      // RootItem.qml
      import QtQuick
      import QtQuick.Controls.Basic
      
      Item {
          id: root
          width: 640
          height: 480
      
          property double scaleFactor: 2.0
      
          Scale {
              id: scale
              xScale: root.scaleFactor
              yScale: root.scaleFactor
          }
          Item {
              id: scaledContent
              transform: scale
      
              ComboBox {
                  id: combobox
                  model: ["Alpha", "Bravo", "Charlie"]
              }
          }
      
          Overlay.overlay.transform: scale // CRASH!
      
          Component.onCompleted: {
              // Still cannot assign/bind here. Component is NOT complete!
              console.log("Overlay is", Overlay.overlay) // "Overlay is null"
      
              //// WORKAROUND OK
              // Qt.callLater(function(){
              //     console.log("Overlay is", Overlay.overlay) // "Overlay is QQuickOverlay(...)"
              //     Overlay.overlay.transform = scale
              // })
          }
      }
      
      
      // main.cpp
      #include <QGuiApplication>
      #include <QQuickView>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
          QQuickView view(QUrl("qrc:/RootItem.qml"));
          view.show();
      
          return app.exec();
      }
      

       

      Workaround
      Don't bind the value declaratively. Assign it one event loop iteration AFTER the Component.completed signal is emitted.

      (We cannot do it directly inside the Component.onCompleted handler because Overlay.overlay is still null then ("TypeError: Value is null and could not be converted to an object")

      Attachments

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

        Activity

          People

            vhilshei Volker Hilsheimer
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: