protected:
virtual void propertyWritten(int index);
virtual void propertyCreated(int, QMetaPropertyBuilder &);
-
+ virtual int createProperty(const char *, const char *);
private:
QDeclarativePropertyMap *map;
QDeclarativePropertyMapPrivate *priv;
QDeclarativePropertyMapMetaObject *mo;
QStringList keys;
void emitChanged(const QString &key, const QVariant &value);
+ bool validKeyName(const QString& name);
};
+bool QDeclarativePropertyMapPrivate::validKeyName(const QString& name)
+{
+ //The following strings shouldn't be used as property names
+ return name != QLatin1String("keys")
+ && name != QLatin1String("valueChanged")
+ && name != QLatin1String("QObject")
+ && name != QLatin1String("destroyed")
+ && name != QLatin1String("deleteLater");
+}
+
void QDeclarativePropertyMapPrivate::emitChanged(const QString &key, const QVariant &value)
{
Q_Q(QDeclarativePropertyMap);
priv->keys.append(QString::fromUtf8(b.name()));
}
+int QDeclarativePropertyMapMetaObject::createProperty(const char *name, const char *value)
+{
+ if (!priv->validKeyName(name))
+ return -1;
+ return QDeclarativeOpenMetaObject::createProperty(name, value);
+}
+
/*!
\class QDeclarativePropertyMap
\brief The QDeclarativePropertyMap class allows you to set key-value pairs that can be used in QML bindings.
void QDeclarativePropertyMap::insert(const QString &key, const QVariant &value)
{
Q_D(QDeclarativePropertyMap);
- //The following strings shouldn't be used as property names
- if (key != QLatin1String("keys")
- && key != QLatin1String("valueChanged")
- && key != QLatin1String("QObject")
- && key != QLatin1String("destroyed")
- && key != QLatin1String("deleteLater")) {
+
+ if (d->validKeyName(key)) {
d->mo->setValue(key.toUtf8(), value);
} else {
qWarning() << "Creating property with name"
void count();
void crashBug();
+ void QTBUG_17868();
};
void tst_QDeclarativePropertyMap::insert()
delete obj;
}
+void tst_QDeclarativePropertyMap::QTBUG_17868()
+{
+ QDeclarativePropertyMap map;
+
+ QDeclarativeEngine engine;
+ QDeclarativeContext context(&engine);
+ context.setContextProperty("map", &map);
+ map.insert("key", 1);
+ QDeclarativeComponent c(&engine);
+ c.setData("import QtQuick 2.0\nItem {property bool error:false; Component.onCompleted: {try{console.log(map.keys());}catch(e) {error=true;}}}",QUrl());
+ QObject *obj = c.create(&context);
+ QVERIFY(obj);
+ QVERIFY(!obj->property("error").toBool());
+ delete obj;
+
+}
+
QTEST_MAIN(tst_QDeclarativePropertyMap)
#include "tst_qdeclarativepropertymap.moc"