diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-10-12 15:56:00 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-12-07 13:50:01 +0100 |
commit | ee9e3a10d967874eddc5400b2b7aa36950140b9b (patch) | |
tree | 0765f56ac0ea367140b241235eb571b295d152d1 /tests/auto/qml/qmltc_qprocess | |
parent | a354d91b885b16e6246d7ff166244b31d33f56a7 (diff) |
qmltc: fix handlers for c++-signals
Allow qmltc to generate handlers for c++-defined signals with const
parameters by changing the safeguard to avoid type mismatch between
slots and signals.
First, remove the qOverload in the generated QObject::connect call to
be able the connect slots and signals with different types (namely,
pass by const references and pass by value should be interchangeable but
is not allowed by qOverload).
Second, save in QQmlJSMetaParameter when types are passed by pointer.
Like this, qqmljsimportvisitor can check if a value type is indeed
passed by value or const reference in a C++ signal. The same for reference
types that need to be passed by (const and non-const) pointer.
Print a message when an type is passed by argument in an incompatible
way instead of letting qmltc generate uncompilable code, which makes the
compiler print out cryptical messages.
Third, add a qqmlcpptypehelpers template that decides if value types
should be passed by value or reference, by letting the c++ compiler
check if sizeof(T) > 3*sizeof(void*).
Fixes: QTBUG-107625
Fixes: QTBUG-107622
Change-Id: I1a00532df591d10f74c1fd00dff5b7fccf40cb22
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltc_qprocess')
4 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt index 04d2084d4f..d936e2c757 100644 --- a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt +++ b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt @@ -20,6 +20,8 @@ qt6_add_qml_module(tst_qmltc_qprocess AUTO_RESOURCE_PREFIX SOURCES cpptypes/testtype.h + DEPENDENCIES + QtQuick/auto QML_FILES data/dummy.qml data/inlineComponentInvalidAlias.qml @@ -30,6 +32,7 @@ qt6_add_qml_module(tst_qmltc_qprocess data/inlineComponentWithEnum.qml data/singletonUncreatable.qml data/uncreatable.qml + data/invalidSignalHandlers.qml ) set(common_libraries diff --git a/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h b/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h index 6082870c76..2130004def 100644 --- a/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h +++ b/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h @@ -7,6 +7,7 @@ #include <QtQmlIntegration/qqmlintegration.h> #include <QtCore/qobject.h> #include <QtQml/qqmlregistration.h> +#include <QtGui/qfont.h> class TypeWithVersionedAlias : public QObject { @@ -67,6 +68,19 @@ class NormalType : public QObject } }; +class TypeWithSignals : public QObject +{ + Q_OBJECT + QML_ELEMENT +public: +Q_SIGNALS: + void signalWithConstPointerToGadget(const QFont *); // not allowed + void signalWithConstPointerToGadgetConst(const QFont *const); // not allowed + void signalWithPointerToGadgetConst(QFont *const); // not allowed + void signalWithPointerToGadget(QFont *); // not allowed + void signalWithPrimitivePointer(int *); + void signalWithConstPrimitivePointer(const int *); +}; #endif // TESTTYPE_H diff --git a/tests/auto/qml/qmltc_qprocess/data/invalidSignalHandlers.qml b/tests/auto/qml/qmltc_qprocess/data/invalidSignalHandlers.qml new file mode 100644 index 0000000000..a2a100ab3b --- /dev/null +++ b/tests/auto/qml/qmltc_qprocess/data/invalidSignalHandlers.qml @@ -0,0 +1,10 @@ + +TypeWithSignals +{ + onSignalWithConstPointerToGadget: (x) => { console.log(x); } + onSignalWithConstPointerToGadgetConst: (x) => { console.log(x); } + onSignalWithPointerToGadgetConst: (x) => { console.log(x); } + onSignalWithPointerToGadget: (x) => { console.log(x); } + onSignalWithPrimitivePointer: (x) => { console.log(x); } + onSignalWithConstPrimitivePointer: (x) => { console.log(x); } +} diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp index 04b3426298..1cea44206f 100644 --- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp +++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp @@ -50,6 +50,7 @@ private slots: void invalidAliasRevision(); void topLevelComponent(); void dashesInFilename(); + void invalidSignalHandlers(); }; #ifndef TST_QMLTC_QPROCESS_RESOURCES @@ -241,5 +242,24 @@ void tst_qmltc_qprocess::dashesInFilename() } } +void tst_qmltc_qprocess::invalidSignalHandlers() +{ + { + const auto errors = runQmltc(u"invalidSignalHandlers.qml"_s, false); + QVERIFY(errors.contains( + u"invalidSignalHandlers.qml:4:5: Type QFont of parameter in signal called signalWithConstPointerToGadget should be passed by value or const reference to be able to compile onSignalWithConstPointerToGadget. [signal-handler-parameters]"_s)); + QVERIFY(errors.contains( + u"invalidSignalHandlers.qml:5:5: Type QFont of parameter in signal called signalWithConstPointerToGadgetConst should be passed by value or const reference to be able to compile onSignalWithConstPointerToGadgetConst. [signal-handler-parameters]"_s)); + QVERIFY(errors.contains( + u"invalidSignalHandlers.qml:6:5: Type QFont of parameter in signal called signalWithPointerToGadgetConst should be passed by value or const reference to be able to compile onSignalWithPointerToGadgetConst. [signal-handler-parameters]"_s)); + QVERIFY(errors.contains( + u"invalidSignalHandlers.qml:7:5: Type QFont of parameter in signal called signalWithPointerToGadget should be passed by value or const reference to be able to compile onSignalWithPointerToGadget. [signal-handler-parameters]"_s)); + QVERIFY(errors.contains( + u"invalidSignalHandlers.qml:8:5: Type int of parameter in signal called signalWithPrimitivePointer should be passed by value or const reference to be able to compile onSignalWithPrimitivePointer. [signal-handler-parameters]"_s)); + QVERIFY(errors.contains( + u"invalidSignalHandlers.qml:9:5: Type int of parameter in signal called signalWithConstPrimitivePointer should be passed by value or const reference to be able to compile onSignalWithConstPrimitivePointer. [signal-handler-parameters]"_s)); + } +} + QTEST_MAIN(tst_qmltc_qprocess) #include "tst_qmltc_qprocess.moc" |