diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-10-12 15:56:00 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2022-11-11 17:33:12 +0100 |
commit | fa1a28852369786a580cc7e0e37bc36dc905b81d (patch) | |
tree | 09e89800f308fd11c0d5e29a226375387c962d33 /tests/auto/qml/qmltyperegistrar | |
parent | edc01fbfa430d6f0ce66f1871ab28e0f691ee252 (diff) |
qmltyperegistrar: add IsConstant for method parameters
Mark method parameters with IsConstant instead of including "const " in
the typename, which makes type resolution in the qml compilers
impossible. This also avoids a crash in qmltc happening when qmltc sees
a signal defined in C++ that has a const parameter.
When qmltyperegistrar writes out the types in the qmltypes, check if it
starts with a const, remove it and add instead IsConstant: true. The
name returned by MOC is normalized so no need to check for "volatile
const" or "const volatile" (its always the latter) and no need to
filter out for extra whitespace.
Once the const is read by the qmltypes reader, propagate the
const-information around using a newly introduced enum called
QQmlJSMetaMethod::PConstness that can currently be
Const or NonConst.
Also add the isConstant property to the Parameter.qml in the tooling
module.
Add a test to see if the IsConstant information is written into the
qmltypes.
This is also required for QTBUG-107625.
Fixes: QTBUG-108147
Task-number: QTBUG-107625
Change-Id: I13bda0a27fe83867f259b751468788128fec82ed
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltyperegistrar')
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/foo.h | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp | 21 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | 1 |
3 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltyperegistrar/foo.h b/tests/auto/qml/qmltyperegistrar/foo.h index 57b771e4eb..7872c35c17 100644 --- a/tests/auto/qml/qmltyperegistrar/foo.h +++ b/tests/auto/qml/qmltyperegistrar/foo.h @@ -12,6 +12,12 @@ class Bbb : public QObject Q_OBJECT public: Bbb(QObject *parent = nullptr) : QObject(parent) {} + +Q_SIGNALS: + void mySignal(QObject *myObject, const QObject *myConstObject, QObject const *myConstObject2, + QObject *const myObject2, const QObject *const myConstObject3); + void myVolatileSignal(volatile const QObject *a, const volatile QObject *b, + volatile QObject *nonConst); }; class Ccc : public QObject diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp index 19a18797bf..6bfe39d420 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -415,4 +415,25 @@ void tst_qmltyperegistrar::duplicateExportWarnings() r.write(output); } +void tst_qmltyperegistrar::hasIsConstantInParameters() +{ + QVERIFY(qmltypesData.contains(R"( Signal { + name: "mySignal" + Parameter { name: "myObject"; type: "QObject"; isPointer: true } + Parameter { name: "myConstObject"; type: "QObject"; isPointer: true; isConstant: true } + Parameter { name: "myConstObject2"; type: "QObject"; isPointer: true; isConstant: true } + Parameter { name: "myObject2"; type: "QObject"; isPointer: true } + Parameter { name: "myConstObject3"; type: "QObject"; isPointer: true; isConstant: true } + } +)")); + + QVERIFY(qmltypesData.contains(R"(Signal { + name: "myVolatileSignal" + Parameter { name: "a"; type: "volatile QObject"; isPointer: true; isConstant: true } + Parameter { name: "b"; type: "volatile QObject"; isPointer: true; isConstant: true } + Parameter { name: "nonConst"; type: "volatile QObject"; isPointer: true } + } +)")); +} + QTEST_MAIN(tst_qmltyperegistrar) diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h index 7bea3a0b83..e6e9b76e69 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -527,6 +527,7 @@ private slots: void immediateNames(); void derivedFromForeignPrivate(); void methodReturnType(); + void hasIsConstantInParameters(); #ifdef QT_QUICK_LIB void foreignRevisionedProperty(); |