Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.15.8, 6.4
-
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
- mentioned in
-
Page Loading...
For Gerrit Dashboard: QTBUG-100260 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
393053,2 | QQmlData: tag singletons | dev | qt/qtdeclarative | Status: DEFERRED | +1 | 0 |
393054,6 | QQmlAdaptorModel: Do not use reparenting for lifetime managemment | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
393686,3 | QQmlAdaptorModel: Do not use reparenting for lifetime managemment | 6.3 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
393700,3 | QQmlAdaptorModel: Do not use reparenting for lifetime managemment | 6.2 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
395053,4 | QQmlAdaptorModel: Do not use reparenting for lifetime managemment | tqtc/lts-5.15 | qt/tqtc-qtdeclarative | Status: MERGED | +2 | 0 |