diff options
-rw-r--r-- | src/qml/Qt6QmlBuildInternals.cmake | 2 | ||||
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 20 | ||||
-rw-r--r-- | src/qmltyperegistrar/qmltyperegistrar.cpp | 12 | ||||
-rw-r--r-- | src/qmltyperegistrar/qmltypes.prf | 4 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/BLACKLIST | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro | 1 |
9 files changed, 57 insertions, 0 deletions
diff --git a/src/qml/Qt6QmlBuildInternals.cmake b/src/qml/Qt6QmlBuildInternals.cmake index a9b20235ad..d25c987fc9 100644 --- a/src/qml/Qt6QmlBuildInternals.cmake +++ b/src/qml/Qt6QmlBuildInternals.cmake @@ -42,6 +42,7 @@ function(qt_internal_add_qml_module target) OPTIONAL_IMPORTS TYPEINFO DEPENDENCIES + PAST_MAJOR_VERSIONS ) qt_parse_all_arguments(arg "qt_add_qml_module" @@ -143,6 +144,7 @@ function(qt_internal_add_qml_module target) TARGET_PATH ${arg_TARGET_PATH} URI ${arg_URI} VERSION ${arg_VERSION} + PAST_MAJOR_VERSIONS ${arg_PAST_MAJOR_VERSIONS} QML_FILES ${arg_QML_FILES} IMPORTS "${arg_IMPORTS}" OPTIONAL_IMPORTS "${arg_OPTIONAL_IMPORTS}" diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index c6b11d5ba1..51fe4cac14 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -41,6 +41,9 @@ # DEPENDENCIES: List of QML Module dependencies and their versions. The module # and its version must be separated via a slash(/). E.g. QtQuick/2.0 # +# PAST_MAJOR_VERSIONS: List of past major versions this QML module was available +# in. Ensures that the module can be imported when using these major versions. +# # QML_FILES: List of Qml files. See qt6_target_qml_files for more information # on how to specify additional properties on qml files. (OPTIONAL) # @@ -117,6 +120,7 @@ function(qt6_add_qml_module target) IMPORTS OPTIONAL_IMPORTS DEPENDENCIES + PAST_MAJOR_VERSIONS ) cmake_parse_arguments(arg @@ -439,6 +443,10 @@ function(qt6_add_qml_module target) endif() endif() + if (arg_PAST_MAJOR_VERSIONS) + set_target_properties(${target} PROPERTIES QT_QML_PAST_MAJOR_VERSIONS "${arg_PAST_MAJOR_VERSIONS}") + endif() + # Generate meta types data if (arg_GENERATE_QMLTYPES) qt6_qml_type_registration(${target}) @@ -664,6 +672,18 @@ function(qt6_qml_type_registration target) --minor-version=${minor_version} ) + # Add past minor versions + get_target_property(past_major_versions ${target} QT_QML_PAST_MAJOR_VERSIONS) + + if (past_major_versions OR past_major_versions STREQUAL "0") + foreach (past_major_version ${past_major_versions}) + list(APPEND cmd_args + --past-major-version ${past_major_version} + ) + endforeach() + endif() + + # Run a script to recursively evaluate all the metatypes.json files in order # to collect all foreign types. string(TOLOWER "${target}_qmltyperegistrations.cpp" type_registration_cpp_file_name) diff --git a/src/qmltyperegistrar/qmltyperegistrar.cpp b/src/qmltyperegistrar/qmltyperegistrar.cpp index bf3c4c94d4..07d7955727 100644 --- a/src/qmltyperegistrar/qmltyperegistrar.cpp +++ b/src/qmltyperegistrar/qmltyperegistrar.cpp @@ -106,6 +106,12 @@ int main(int argc, char **argv) importNameOption.setValueName(QStringLiteral("module name")); parser.addOption(importNameOption); + QCommandLineOption pastMajorVersionOption(QStringLiteral("past-major-version")); + pastMajorVersionOption.setDescription(QStringLiteral("Past major version to use for type and module " + "registrations.")); + pastMajorVersionOption.setValueName(QStringLiteral("past major version")); + parser.addOption(pastMajorVersionOption); + QCommandLineOption majorVersionOption(QStringLiteral("major-version")); majorVersionOption.setDescription(QStringLiteral("Major version to use for type and module " "registrations.")); @@ -188,8 +194,14 @@ int main(int argc, char **argv) fprintf(output, "void %s()\n{", qPrintable(functionName)); const auto majorVersion = parser.value(majorVersionOption); + const auto pastMajorVersions = parser.values(pastMajorVersionOption); const auto minorVersion = parser.value(minorVersionOption); + for (const auto &version : pastMajorVersions) { + fprintf(output, "\n qmlRegisterModule(\"%s\", %s, 0);\n qmlRegisterModule(\"%s\", %s, 254);", + qPrintable(module), qPrintable(version), qPrintable(module), qPrintable(version)); + } + if (minorVersion.toInt() != 0) { fprintf(output, "\n qmlRegisterModule(\"%s\", %s, 0);", qPrintable(module), qPrintable(majorVersion)); diff --git a/src/qmltyperegistrar/qmltypes.prf b/src/qmltyperegistrar/qmltypes.prf index e02d425f2a..0b857ad099 100644 --- a/src/qmltyperegistrar/qmltypes.prf +++ b/src/qmltyperegistrar/qmltypes.prf @@ -63,6 +63,10 @@ QML_TYPEREGISTRAR_FLAGS = \ --minor-version=$$QML_IMPORT_MINOR_VERSION \ --foreign-types=$$join(QML_FOREIGN_METATYPES, ',') +!isEmpty(QML_PAST_MAJOR_VERSIONS) { + for(past_major_version,QML_PAST_MAJOR_VERSIONS): QML_TYPEREGISTRAR_FLAGS += --past-major-version $$past_major_version +} + !isEmpty(MODULE_PRIVATE_INCLUDES): QML_TYPEREGISTRAR_FLAGS += --private-includes METATYPES_JSON = $${TARGET_BASENAME}_metatypes.json diff --git a/tests/auto/qml/qmltyperegistrar/BLACKLIST b/tests/auto/qml/qmltyperegistrar/BLACKLIST new file mode 100644 index 0000000000..6563288d0c --- /dev/null +++ b/tests/auto/qml/qmltyperegistrar/BLACKLIST @@ -0,0 +1,3 @@ +[pastMajorVersions] +windows # QTBUG-88381 + diff --git a/tests/auto/qml/qmltyperegistrar/CMakeLists.txt b/tests/auto/qml/qmltyperegistrar/CMakeLists.txt index d581589f4d..db8fa4b1d6 100644 --- a/tests/auto/qml/qmltyperegistrar/CMakeLists.txt +++ b/tests/auto/qml/qmltyperegistrar/CMakeLists.txt @@ -32,6 +32,7 @@ target_compile_definitions(tst_qmltyperegistrar PRIVATE BUILD_WITH_CMAKE) # spec set_target_properties(tst_qmltyperegistrar PROPERTIES QT_QML_MODULE_VERSION 1.0 QT_QML_MODULE_URI QmlTypeRegistrarTest + QT_QML_PAST_MAJOR_VERSIONS 0 # special case QT_QMLTYPES_FILENAME tst_qmltyperegistrar.qmltypes ) diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp index 4b8502c501..2f5759d697 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -30,9 +30,14 @@ #include <QtTest/qtest.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qfile.h> +#include <QtQml/QQmlEngine> +#include <QtQml/QQmlComponent> + +#define QT_FORCE_ASSERTS 1 void tst_qmltyperegistrar::initTestCase() { + Q_ASSERT(QCoreApplication::instance()); QFile file(QCoreApplication::applicationDirPath() + "/tst_qmltyperegistrar.qmltypes"); QVERIFY(file.open(QIODevice::ReadOnly)); qmltypesData = file.readAll(); @@ -100,4 +105,12 @@ void tst_qmltyperegistrar::restrictToImportVersion() QVERIFY(!qmltypesData.contains("paletteChanged")); // Added in version 6.0 } +void tst_qmltyperegistrar::pastMajorVersions() +{ + QQmlEngine engine; + QQmlComponent c(&engine); + c.setData("import QML\nimport QmlTypeRegistrarTest 0.254\nQtObject {}", QUrl()); + QVERIFY2(!c.isError(), qPrintable(c.errorString())); +} + QTEST_MAIN(tst_qmltyperegistrar) diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h index d48f61cc10..3c00e04357 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -123,6 +123,7 @@ private slots: void accessSemantics(); void isBindable(); void restrictToImportVersion(); + void pastMajorVersions(); private: QByteArray qmltypesData; diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro index fe21b122c2..4b6303ec33 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.pro @@ -15,6 +15,7 @@ QMLTYPES_FILENAME = tst_qmltyperegistrar.qmltypes QML_FOREIGN_METATYPES += foreign/foreign_metatypes.json QML_IMPORT_NAME = QmlTypeRegistrarTest QML_IMPORT_VERSION = 1.0 +QML_PAST_MAJOR_VERSIONS = 0 INCLUDEPATH += foreign LIBS += -Lforeign -lforeign |