summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptextqobject
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-01-19 10:16:36 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-01-19 10:24:13 (GMT)
commited5fed36f38b9de0452cc427db679266d249f216 (patch)
treedff3381c84823d8db8d505c52ba307c1f20cf014 /tests/auto/qscriptextqobject
parent3214e477ccc3eae5c61b357696095f1f460fafbb (diff)
downloadQt-ed5fed36f38b9de0452cc427db679266d249f216.zip
Qt-ed5fed36f38b9de0452cc427db679266d249f216.tar.gz
Qt-ed5fed36f38b9de0452cc427db679266d249f216.tar.bz2
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/auto/qscriptextqobject')
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index de9d37e..b4ce561 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"