From 4f1ed0948b99af617fa978f0f1b72e48a9fe774f Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 21 Oct 2013 14:43:19 +0200 Subject: Avoid crash when a QML signal is connected to a non-void slot Don't pass a QVariant pointer for the return value when we're not interested in it and the return type might not even be a QVariant (that would be only true for QML methods). Task-number: QTBUG-32801 Change-Id: I8f14e40d8f94caef7e3d086b776735f0484dbf0e Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlecmascript/data/qtbug_32801.qml | 10 ++++++++++ tests/auto/qml/qqmlecmascript/testtypes.h | 1 + tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 13 +++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/auto/qml/qqmlecmascript/data/qtbug_32801.qml (limited to 'tests/auto/qml/qqmlecmascript') diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_32801.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_32801.qml new file mode 100644 index 0000000000..c305ba7178 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_32801.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + signal testSignal(string arg) + + function emitTestSignal() { + testSignal("test") + } +} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index c6f6de7337..0fdcdafb95 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -268,6 +268,7 @@ public slots: void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; } void v8function(QQmlV4Function*); void registeredFlagMethod(Qt::MouseButtons v) { m_buttons = v; } + QString slotWithReturnValue(const QString &arg) { return arg; } private: friend class tst_qqmlecmascript; diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 47b7a6640c..e764ae783c 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -306,6 +306,7 @@ private slots: void jsOwnedObjectsDeletedOnEngineDestroy(); void numberParsing(); void stringParsing(); + void qtbug_32801(); private: // static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -7288,6 +7289,18 @@ void tst_qqmlecmascript::stringParsing() } } +void tst_qqmlecmascript::qtbug_32801() +{ + QQmlComponent component(&engine, testFileUrl("qtbug_32801.qml")); + + QScopedPointer obj(component.create()); + QVERIFY(obj != 0); + + // do not crash when a QML signal is connected to a non-void slot + connect(obj.data(), SIGNAL(testSignal(QString)), obj.data(), SLOT(slotWithReturnValue(QString))); + QVERIFY(QMetaObject::invokeMethod(obj.data(), "emitTestSignal")); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" -- cgit v1.2.3