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

Crash on access after using QML singleton as a model

    XMLWordPrintable

Details

    • 6901eacff4 (qt/qtdeclarative/dev) 6901eacff4 (qt/tqtc-qtdeclarative/dev) a02496b639 (qt/qtdeclarative/6.3) ce8db06725 (qt/qtdeclarative/6.2) ce8db06725 (qt/tqtc-qtdeclarative/6.2) a02496b639 (qt/tqtc-qtdeclarative/6.3) ce8db06725 (qt/qtdeclarative/6.2.4)

    Description

      This model is registered as a QML singleton:

      class SingletonModel : public QStringListModel
      {
          Q_OBJECT
      public:
          SingletonModel(QObject* parent) : QStringListModel(parent) { }
      };
      // ...
      qmlRegisterSingletonType<SingletonModel>(uri, 1, 0, "SingletonModel",
          [](QQmlEngine* engine, QJSEngine*) -> QObject* { return new SingletonModel; });
      

      If ListView is destroyed with that object as the model, the singleton breaks and will crash on next access:

              Component {
                  id: view
                  ListView {
                      model: SingletonModel
                  }
              }
              function test_singletonModelCrash() {
                  SingletonModel.objectName = "model"
                  var o = view.createObject(root)
                  // no crash: o.model = null
                  o.destroy()
                  compare(SingletonModel.objectName, "model")
                  wait(1)
                  // crash
                  compare(SingletonModel.objectName, "model")
              }
      
      QV4::QQmlTypeWrapper::virtualResolveLookupGetter (object=<optimized out>, engine=<optimized out>, lookup=<optimized out>) at qml/qqmltypewrapper.cpp:462
      462	                               lookup->qobjectLookup.ic = val->objectValue()->internalClass();
      

      The SingletonModel instance is not destroyed. Setting a QObject parent or CppOwnership prevents the bug, but from what I understand the code above is valid and the engine should have "ownership".

      Attachments

        Issue Links

          Activity

            People

              qtqmlteam Qt Qml Team User
              special John Brooks
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: