aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpropertycache.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2014-12-01 14:37:09 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-12-13 01:36:30 +0100
commit450883d16b51b326e5d517de1517e14bf906df69 (patch)
tree748757eaf094e5b1289884730191658b95140fd3 /src/qml/qml/qqmlpropertycache.cpp
parenta3d89b09b77c268f3c279f207c1df0aa1415dea9 (diff)
Read and write QObject pointer properties in QML without registration.
Previously, accessing QObject pointer properties from QML would require these types to be registered with qRegisterMetaType(), but this shouldn't be necessary if we're able to read/write the property, because the moc generates code that calls qRegisterMetaType in the static meta-call implementation. So when resolving a property in the property cache and we can't resolve, fall back to placing the static meta-call to register the type, similar to what QMetaType::userType() does. Change-Id: Ic8b00ed93a1e5e42cf7aaaf1c355e89557485c59 Reviewed-by: Christopher Adams <chris.adams@jollamobile.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache.cpp')
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index ff711605be..535fb334c4 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -799,8 +799,30 @@ void QQmlPropertyCache::resolve(QQmlPropertyData *data) const
data->propType = QMetaType::type(data->propTypeName);
- if (!data->isFunction())
+ if (!data->isFunction()) {
+ if (data->propType == QMetaType::UnknownType) {
+ const QMetaObject *mo = _metaObject;
+ QQmlPropertyCache *p = _parent;
+ while (p && (!mo || _ownMetaObject)) {
+ mo = p->_metaObject;
+ p = p->_parent;
+ }
+
+ int propOffset = mo->propertyOffset();
+ if (mo && data->coreIndex < propOffset + mo->propertyCount()) {
+ while (data->coreIndex < propOffset) {
+ mo = mo->superClass();
+ propOffset = mo->propertyOffset();
+ }
+
+ int registerResult = -1;
+ void *argv[] = { &registerResult };
+ mo->static_metacall(QMetaObject::RegisterPropertyMetaType, data->coreIndex - propOffset, argv);
+ data->propType = registerResult == -1 ? QMetaType::UnknownType : registerResult;
+ }
+ }
data->flags |= flagsForPropertyType(data->propType, engine);
+ }
data->flags &= ~QQmlPropertyData::NotFullyResolved;
}