aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-08-23 10:42:35 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-09-01 09:46:03 +0200
commitfa94a35ee718e2a83440b66a6dd57e53a0aee500 (patch)
treed4b6923253b800f4dccd190c411f45e6f09bcfd2 /tests
parent6fa4d45b0d321d5d2c935ed000467b167d0c1b27 (diff)
QmlCompiler: Prevent lookup of value type where we need an object type
With a particular nefarious combination of Q_GADGET and inheritance from QObject you can make QmlCompiler believe a type is a value type even though it is actually an object type. We never want to touch such a thing. There was a safe guard against this when looking up the type from the scope, but by putting it in a type namespace you could circumvent it. Refactor the code to apply to both cases the same way. Fixes: QTBUG-104556 Fixes: QTBUG-105608 Change-Id: I8a690e2b6f78fcaba0911a93504cde0d2c7dde0d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 0a8fe228f6bb65afe08f1bc203653266fa204ba5)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/failures.qml4
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h23
3 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index f3e608a6ae..7010500fba 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -3,6 +3,7 @@ set(cpp_sources
birthdayparty.cpp birthdayparty.h
cppbaseclass.h
dynamicmeta.h
+ gadgetwithenum.h
invisible.h
objectwithmethod.h
person.cpp person.h
diff --git a/tests/auto/qml/qmlcppcodegen/data/failures.qml b/tests/auto/qml/qmlcppcodegen/data/failures.qml
index 39268d84ce..16dd0c764a 100644
--- a/tests/auto/qml/qmlcppcodegen/data/failures.qml
+++ b/tests/auto/qml/qmlcppcodegen/data/failures.qml
@@ -1,5 +1,6 @@
import QtQml
import TestTypes
+import TestTypes as TT2
import Ambiguous 1.2
QtObject {
@@ -35,4 +36,7 @@ QtObject {
signal bar()
// Cannot assign potential undefined
onFoo: objectName = self.bar()
+
+ property int enumFromGadget1: GadgetWithEnum.CONNECTED + 1
+ property int enumFromGadget2: TT2.GadgetWithEnum.CONNECTED + 1
}
diff --git a/tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h b/tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h
new file mode 100644
index 0000000000..d146b9f654
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h
@@ -0,0 +1,23 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#ifndef GADGETWITHENUM_H
+#define GADGETWITHENUM_H
+
+#include <QtCore/qobject.h>
+#include <QtQmlIntegration/qqmlintegration.h>
+
+class GadgetWithEnum : public QObject {
+ Q_GADGET
+ QML_ELEMENT
+
+public:
+ enum State {
+ DISCONNECTED,
+ CONNECTING,
+ CONNECTED
+ };
+ Q_ENUM(State)
+};
+
+#endif // GADGETWITHENUM_H