aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-11 15:09:53 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-12 16:18:28 +0000
commitb7412dc86608207cba84538cb962e4300dfe42c1 (patch)
tree34d831189d56e5b19e7b52294f96eb1600fb4977 /tests/auto
parent8784a2778063cf928b27a908f6580ed37cb4035d (diff)
QML: Warn about usage of injected signal parameters
You should declare functions with formal parameters if you want to use parameters passed by the signal. We need to generate two different warnings because there are two code paths by which such parameters are injected. If we compile with qmlcachegen, it simply inserts a lookup instruction in to the byte code. This lookup then triggers our special hack expressly made for signal parameters. If we don't compile using qmlcachegen, a function declaration with formal parameters is synthesized. We mark those formal parameters as injected and warn if we see one of them used. [ChangeLog][QML][Important Behavior Changes] The automatic injection of signal parameters into signal handlers is deprecated. This is because we cannot determine the names of the signal parameters at compile time. Furthermore, also for human readers it is difficult to discern between arguments, context properties, properties of the current object, and properties of the root object of the component. Requiring the signal parameters to be explicitly named resolves some of this confusion. You can turn the deprecation warning off using the "qt.qml.compiler" and "qt.qml.context" logging categories. Task-number: QTBUG-89943 Change-Id: If0a5082adb735a73efd793868b3a55bc7d694cbe Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> (cherry picked from commit df70d4f76f9c1c7b3de9ae91877df803c18b1264) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 46fb83ac9f..66beb839f0 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -350,6 +350,7 @@ private slots:
void multiExtension();
void invalidInlineComponent();
+ void warnOnInjectedParameters();
private:
QQmlEngine engine;
@@ -6167,6 +6168,24 @@ void tst_qqmllanguage::invalidInlineComponent()
QVERIFY(c.errorString().contains("\"Window.visibility\" is not available in QtQuick 2.0."));
}
+void tst_qqmllanguage::warnOnInjectedParameters()
+{
+ QQmlEngine e;
+ QQmlComponent c(&engine);
+ QTest::ignoreMessage(QtWarningMsg, "qrc:/foo.qml:4:18 Parameter \"bar\" is not declared."
+ " Injection of parameters into signal handlers is deprecated."
+ " Use JavaScript functions with formal parameters instead.");
+ c.setData("import QtQml\n"
+ "QtObject {\n"
+ " signal foo(bar: string)\n"
+ " onFoo: print(bar)\n"
+ " Component.onCompleted: foo('baz')\n"
+ "}", QUrl("qrc:/foo.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QTest::ignoreMessage(QtDebugMsg, "baz");
+ QScopedPointer<QObject> o(c.create());
+}
+
void tst_qqmllanguage::qtbug_86482()
{
QQmlEngine engine;