From c5f7b5d382b14ff73fc40044c395148d15844c2f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 18 Jan 2010 11:43:36 +1000 Subject: Handle whitespace in Connection signal signatures. Task-number: QTBUG-7210 --- src/declarative/util/qmlconnection.cpp | 2 +- .../declarative/qmlconnection/data/trimming.qml | 10 ++++++++++ .../declarative/qmlconnection/tst_qmlconnection.cpp | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmlconnection/data/trimming.qml diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp index f5fbd3f..800fd6b 100644 --- a/src/declarative/util/qmlconnection.cpp +++ b/src/declarative/util/qmlconnection.cpp @@ -172,7 +172,7 @@ void QmlConnection::connectIfValid() if (lparen >= 0 && d->signal.length() > lparen+2) { QStringList l = d->signal.mid(lparen+1,d->signal.length()-lparen-2).split(QLatin1Char(',')); foreach (const QString &s, l) { - sigparams.append(s.toUtf8()); + sigparams.append(s.trimmed().toUtf8()); } } QString signalname = d->signal.left(lparen); diff --git a/tests/auto/declarative/qmlconnection/data/trimming.qml b/tests/auto/declarative/qmlconnection/data/trimming.qml new file mode 100644 index 0000000..c27dc46 --- /dev/null +++ b/tests/auto/declarative/qmlconnection/data/trimming.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Item { + id: screen; width: 50 + + property string tested + signal testMe(int param1, string param2) + + Connection { sender: screen; signal: "testMe(param1, param2)"; script: screen.tested = param2 + param1 } +} diff --git a/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp b/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp index b21da48..3d9ee46 100644 --- a/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp +++ b/tests/auto/declarative/qmlconnection/tst_qmlconnection.cpp @@ -57,6 +57,7 @@ private slots: void defaultValues(); void properties(); void connection(); + void trimming(); private: QmlEngine engine; @@ -113,6 +114,26 @@ void tst_qmlconnection::connection() delete item; } +void tst_qmlconnection::trimming() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/trimming.qml")); + QmlGraphicsItem *item = qobject_cast(c.create()); + + QVERIFY(item != 0); + + QCOMPARE(item->property("tested").toString(), QString("")); + int index = item->metaObject()->indexOfSignal("testMe(int,QString)"); + QMetaMethod method = item->metaObject()->method(index); + method.invoke(item, + Qt::DirectConnection, + Q_ARG(int, 5), + Q_ARG(QString, "worked")); + QCOMPARE(item->property("tested").toString(), QString("worked5")); + + delete item; +} + QTEST_MAIN(tst_qmlconnection) #include "tst_qmlconnection.moc" -- cgit v0.12