aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2011-09-16 14:06:02 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-19 13:25:39 +0200
commit8de9a07c654492a60726e84332bba43cc7b81dbd (patch)
tree9de928d934c301925fe6fe1e15edf851f73b008b /src
parentc970d47d4ec8bed85acc313e22ddb8bbba55618e (diff)
Unwrap QJSValue from QVariant in QV8Engine::fromVariant
When QML tries to unwrap real value from a QVariant and the value is a QJSValue instance, then no conversion is needed, QJSValue already contains a v8 handle. This patch, for example, solves a problem of emitting QJSValue instance in a signal that has QVariant as an argument. The QJSValue can be unwrapped and used as a normal JS value in a connected slot. This feature may be used also in a plugin model that stores QJSValues internally. Then the model in data() function can return a QJSValue which would be understood by QML. Change-Id: I1d5ede40ce2637123b09839fd848b27ad3af3dda Reviewed-on: http://codereview.qt-project.org/4451 Reviewed-by: Kent Hansen <kent.hansen@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index c10f048a20..7be74f8711 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -341,6 +341,11 @@ v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
} else {
return v8::Null();
}
+ } else if (type == qMetaTypeId<QJSValue>()) {
+ const QJSValue *value = reinterpret_cast<const QJSValue *>(ptr);
+ QJSValuePrivate *valuep = QJSValuePrivate::get(*value);
+ if (valuep->assignEngine(this))
+ return v8::Local<v8::Value>::New(*valuep);
} else if (type == qMetaTypeId<QList<QObject *> >()) {
// XXX Can this be made more by using Array as a prototype and implementing
// directly against QList<QObject*>?
@@ -358,7 +363,6 @@ v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
}
// XXX TODO: To be compatible, we still need to handle:
- // + QJSValue
// + QObjectList
// + QList<int>