aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-02-27 11:27:31 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-02 23:27:24 +0000
commit5dfc97ddf0d5528a80f3a2a6e7f0aaa68b49ce15 (patch)
tree1a42dd744cde3e531d1e1fec892cc5be4a5896da
parent22aafc46ade65ca042d0f2507abc43b9380b4cbc (diff)
qt_add_qml_module: Error out if singleton is marked as internal
A singleton cannot be marked as internal – the qmldir parser cannot even parse such a declaration, and the runtime would have no idea how to deal with such a type. The cmake code so far generated two entries – one line where the type is a singleton, and the other one where the type is declared as internal – with the end result that the type was not treated as a singleton, at least not by qmllint. Once the engine actually supports internal singletons, we would need to adjust the qmldir file to have singleton and internal in one line. As that's not supported so far, we now simply error out with a fatal warning. Task-number: QTBUG-111532 Change-Id: Idf0843c5548b15f79700a45b4197c256a6dda5cd Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> (cherry picked from commit 10a310c089e0d9731067abd6bb56771b51719043) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/Qt6QmlMacros.cmake6
-rw-r--r--tests/auto/cmake/CMakeLists.txt1
-rw-r--r--tests/auto/cmake/test_internal_singleton/CMakeLists.txt23
-rw-r--r--tests/auto/cmake/test_internal_singleton/Test.qml4
4 files changed, 34 insertions, 0 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 6e200079e1..f307c1f4be 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -2054,6 +2054,12 @@ function(qt6_target_qml_sources target)
get_source_file_property(qml_file_singleton ${qml_file_src} QT_QML_SINGLETON_TYPE)
get_source_file_property(qml_file_internal ${qml_file_src} QT_QML_INTERNAL_TYPE)
+ if (qml_file_singleton AND qml_file_internal)
+ message(FATAL_ERROR
+ "${qml_file_src} is marked as both internal and as a "
+ "singleton, but singletons cannot be internal!")
+ endif()
+
if (NOT qml_file_versions)
set(qml_file_versions ${qml_module_files_versions})
endif()
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index 1dc26bbde9..6fb4b6cb2a 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -68,6 +68,7 @@ if(TARGET Qt::Qml)
If(NOT ANDROID) # QML only project cannot run on Android with C++ enty point
_qt_internal_test_expect_pass(qmlquery)
endif()
+ _qt_internal_test_expect_fail(test_internal_singleton)
endif()
if(TARGET Qt::Quick)
diff --git a/tests/auto/cmake/test_internal_singleton/CMakeLists.txt b/tests/auto/cmake/test_internal_singleton/CMakeLists.txt
new file mode 100644
index 0000000000..f1db46a0f9
--- /dev/null
+++ b/tests/auto/cmake/test_internal_singleton/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+
+cmake_minimum_required(VERSION 3.19)
+
+project(test_internal_singleton)
+
+find_package(Qt6 REQUIRED COMPONENTS Qml)
+
+qt_standard_project_setup()
+
+set_source_files_properties(Test.qml PROPERTIES
+ QT_QML_SINGLETON_TYPE TRUE
+ QT_QML_INTERNAL_TYPE TRUE
+)
+
+qt_add_qml_module(test_internal_singleton
+ URI Controls
+ VERSION 1.0
+ QML_FILES
+ Test.qml
+)
diff --git a/tests/auto/cmake/test_internal_singleton/Test.qml b/tests/auto/cmake/test_internal_singleton/Test.qml
new file mode 100644
index 0000000000..a2eb03bd4e
--- /dev/null
+++ b/tests/auto/cmake/test_internal_singleton/Test.qml
@@ -0,0 +1,4 @@
+pragma singleton
+import QtQml
+
+QtObject {}