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
Pick-to: 6.5 6.4 6.2
Change-Id: Idf0843c5548b15f79700a45b4197c256a6dda5cd
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Fabian Kosmale 2023-02-27 11:27:31 +01:00
parent 024794255d
commit 10a310c089
4 changed files with 34 additions and 0 deletions

View File

@ -2157,6 +2157,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()

View File

@ -110,6 +110,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)

View File

@ -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
)

View File

@ -0,0 +1,4 @@
pragma singleton
import QtQml
QtObject {}