From 9dec5247be84ae4606d5d9baf5b99612c5feba8d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 22 Oct 2009 13:26:28 +0200 Subject: QtScript: Compatibility with 4.5 We must register the same type as they were registered in Qt 4.5 Reported on qt4-preview-feedback mailing list. Reviewed-by: Kent Hansen --- src/script/api/qscriptengine.cpp | 4 ++++ .../qscriptextqobject/tst_qscriptextqobject.cpp | 24 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 360036a..c3c8caf 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -797,6 +797,10 @@ QScriptEnginePrivate::QScriptEnginePrivate() registeredScriptStrings(0), inEval(false) { qMetaTypeId(); + qMetaTypeId >(); +#ifndef QT_NO_QOBJECT + qMetaTypeId(); +#endif JSC::initializeThreading(); // ### hmmm diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp index 320a429..44adf7e 100644 --- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp +++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp @@ -317,6 +317,11 @@ public: Q_INVOKABLE QObject* myInvokableReturningMyQObjectAsQObject() { m_qtFunctionInvoked = 57; return this; } + Q_INVOKABLE QObjectList findObjects() const + { return findChildren(); } + Q_INVOKABLE QList myInvokableNumbers() const + { return QList() << 1 << 2 << 3; } + void emitMySignal() { emit mySignal(); } void emitMySignalWithIntArg(int arg) @@ -493,6 +498,7 @@ protected slots: } private slots: + void registeredTypes(); void getSetStaticProperty(); void getSetDynamicProperty(); void getSetChildren(); @@ -543,6 +549,24 @@ void tst_QScriptExtQObject::cleanup() delete m_myObject; } +// this test has to be first and test that some types are automatically registered +void tst_QScriptExtQObject::registeredTypes() +{ + QScriptEngine e; + QObject *t = new MyQObject; + QObject *c = new QObject(t); + c->setObjectName ("child1"); + + e.globalObject().setProperty("MyTest", e.newQObject(t)); + + QScriptValue v1 = e.evaluate("MyTest.findObjects()[0].objectName;"); + QCOMPARE(v1.toString(), c->objectName()); + + QScriptValue v2 = e.evaluate("MyTest.myInvokableNumbers()"); + QCOMPARE(qscriptvalue_cast >(v2), (QList() << 1 << 2 << 3)); +} + + static QScriptValue getSetProperty(QScriptContext *ctx, QScriptEngine *) { if (ctx->argumentCount() != 0) -- cgit v0.12