-
Bug
-
Resolution: Out of scope
-
P2: Important
-
None
-
4.8.0, 5.0.0
-
None
-
Qt for embedded Linux 4.8
If bindings to a QDeclarativePropertyMap are correctly established depends on the order of the items in the QML file, given that the map is filled during item construction. The following test code produces a window with the text "before.map.key1 = XXX, after.map.key4 = undefined", although the only difference between the "before" and "after" item is their relative position to the text item. Also any updates on the map work only on the "before" item. (The problem is not, that the map property is a (QObject *) instead of a (QDeclarativePropertyMap *), or that it is CONSTANT without NOTIFY, that has been tested already.)
test.cpp:
#include <QtGui/QApplication> #include <QtDeclarative> #include <QDeclarativePropertyMap> #include "qmlapplicationviewer.h" class MyItem : public QObject { Q_OBJECT Q_PROPERTY(QStringList keys READ Keys WRITE SetKeys) Q_PROPERTY(QObject *map READ Map CONSTANT) public: MyItem(QObject *parent = 0) : QObject(parent) {} QStringList Keys() const { return map_.keys(); } QDeclarativePropertyMap *Map() { return &map_; } void SetKeys(const QStringList &keys) { Q_FOREACH(QString key, keys) { if (!map_.contains(key)) { map_.insert(key, QVariant(QString("XXX"))); } } } private: QDeclarativePropertyMap map_; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); QmlApplicationViewer viewer; qmlRegisterType<MyItem>("Test", 1, 0, "MyItem"); viewer.setMainQmlFile(QLatin1String("qml/test.qml")); viewer.showExpanded(); return app.exec(); } #include "test.moc"
test.qml:
import QtQuick 1.0 import Test 1.0 Rectangle { width: 400 height: 200 MyItem { id: before keys: ["key1", "key2", "key3"] Component.onCompleted: console.log("before item completed: " + keys) } Text { text: "before.map.key1 = " + before.map.key1 + ", after.map.key4 = " + after.map.key4 anchors.centerIn: parent } MyItem { id: after keys: ["key4", "key5", "key6"] Component.onCompleted: console.log("after item completed: " + keys) } }