Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.15.5, 6.2.0 Beta3
-
6f36faf96b488330f2388bdc8728d843f14c38f9 (qt/qtdeclarative/dev) 2b88f43894a068dc288c813b291e2ac05f8e4782 (qt/qtdeclarative/6.2)
Description
If a class has a number of Q_PROPERTYs only the first REQUIRED property seems to be required for instantiating the object in Qml. So in a setup where there are 2 properties e.g.
Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged REQUIRED)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged REQUIRED)
setting the property "index" in Qml seems to be enough for the object to be successfully instantiated.
Demo {
id: demo
index: 1
Component.onCompleted: {
console.log("The property 'name' is required but it's value is:", demo.name)
}
}
If the order of the Q_PROPERTYs is swapped in C++ and the test app is rebuilt now there would be an error
QQmlApplicationEngine failed to create component
qrc:/main.qml:10:5: Required property name was not initialized
upon running the test app.
Steps to reproduce the problem:
- run the attached example (it loads the qml without any warnings or errors)
Attachments
For Gerrit Dashboard: QTBUG-96200 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
370322,7 | tst_qqmlcomponent: add more tests for required properties | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
371158,11 | Fix required properties detection in QQmlObjectCreator | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
372702,3 | tst_qqmlcomponent: add more tests for required properties | 6.2 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
372704,3 | Fix required properties detection in QQmlObjectCreator | 6.2 | qt/qtdeclarative | Status: MERGED | +2 | 0 |