diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-01-19 11:16:36 +0100 |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-01-19 11:24:13 +0100 |
commit | ed5fed36f38b9de0452cc427db679266d249f216 (patch) | |
tree | dff3381c84823d8db8d505c52ba307c1f20cf014 /tests | |
parent | 3214e477ccc3eae5c61b357696095f1f460fafbb (diff) | |
download | qt4-tools-ed5fed36f38b9de0452cc427db679266d249f216.tar.gz |
Remove QtScript connection when receiver QObject has been deleted
We don't want to have to listen to the destroyed() signal for every
receiver object of a connection, and likewise we don't want to create
a QObject to handle each connection; instead, remove the connection
lazily at signal emission time after we've detected that the receiver
has been deleted.
Task-number: QTBUG-7313
Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp index de9d37ebc8..b4ce5611d6 100644 --- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp +++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp @@ -532,6 +532,7 @@ private slots: void prototypes(); void objectDeleted(); void connectToDestroyedSignal(); + void emitAfterReceiverDeleted(); private: QScriptEngine *m_engine; @@ -3020,5 +3021,27 @@ void tst_QScriptExtQObject::connectToDestroyedSignal() #endif } +void tst_QScriptExtQObject::emitAfterReceiverDeleted() +{ + for (int x = 0; x < 2; ++x) { + MyQObject *obj = new MyQObject; + QScriptValue scriptObj = m_engine->newQObject(obj); + if (x == 0) { + // Connecting from JS + m_engine->globalObject().setProperty("obj", scriptObj); + QVERIFY(m_engine->evaluate("myObject.mySignal.connect(obj, 'mySlot()')").isUndefined()); + } else { + // Connecting from C++ + qScriptConnect(m_myObject, SIGNAL(mySignal()), scriptObj, scriptObj.property("mySlot")); + } + delete obj; + QSignalSpy signalHandlerExceptionSpy(m_engine, SIGNAL(signalHandlerException(QScriptValue))); + QVERIFY(!m_engine->hasUncaughtException()); + m_myObject->emitMySignal(); + QCOMPARE(signalHandlerExceptionSpy.count(), 0); + QVERIFY(!m_engine->hasUncaughtException()); + } +} + QTEST_MAIN(tst_QScriptExtQObject) #include "tst_qscriptextqobject.moc" |