diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-08-23 10:42:35 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-08-30 18:53:01 +0200 |
commit | 0a8fe228f6bb65afe08f1bc203653266fa204ba5 (patch) | |
tree | 002ae8b3c36566b2cf91eb62bf08d2d88a54fe5f /tests/auto/qml/qmlcppcodegen | |
parent | b50d01891b1adba15c4cfc47ad078d227aa1f491 (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.
Pick-to: 6.2 6.3 6.4
Fixes: QTBUG-104556
Fixes: QTBUG-105608
Change-Id: I8a690e2b6f78fcaba0911a93504cde0d2c7dde0d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/failures.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h | 23 |
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 e7774cb112..9bec7c7890 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -6,6 +6,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 880fa43e07..195165f944 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 { @@ -40,4 +41,7 @@ QtObject { // 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 |