diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt b/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt index d5725099e15..63e2498dff2 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt @@ -2,10 +2,22 @@ cmake_minimum_required(VERSION 3.16) project(%{ProjectName} VERSION 0.1 LANGUAGES CXX) +@if !%{HasQSPSetup} set(CMAKE_AUTOMOC ON) +@endif set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 6.2 REQUIRED COMPONENTS Quick) +find_package(Qt6 %{MinimumSupportedQtVersion} REQUIRED COMPONENTS Quick) + +@if %{HasQSPSetup} +@if %{UsesAutoResourcePrefix} +qt_standard_project_setup( + MIN_VERSION 6.5 +) +@else +qt_standard_project_setup() +@endif +@endif qt_add_executable(%{TargetName} main.cpp @@ -14,7 +26,7 @@ qt_add_executable(%{TargetName} qt_add_qml_module(%{TargetName} URI %{ProjectName} VERSION 1.0 - QML_FILES main.qml + QML_FILES Main.qml ) set_target_properties(%{TargetName} PROPERTIES diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/main.qml.tpl b/share/qtcreator/templates/wizards/projects/qtquickapplication/Main.qml.tpl similarity index 100% rename from share/qtcreator/templates/wizards/projects/qtquickapplication/main.qml.tpl rename to share/qtcreator/templates/wizards/projects/qtquickapplication/Main.qml.tpl diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp b/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp index bdfd80e1c35..155667fb122 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp @@ -10,13 +10,25 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - const QUrl url(u"qrc:/%{JS: value('ProjectName')}/main.qml"_qs); +@if !%{HasLoadFromModule} + const QUrl url(u"qrc:/%{JS: value('ProjectName')}/Main.qml"_qs); +@endif +@if %{HasFailureSignal} + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, + &app, []() { QCoreApplication::exit(-1); }, + Qt::QueuedConnection); +@else QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); +@endif +@if %{HasLoadFromModule} + engine.loadFromModule("%{JS: value('ProjectName')}", "Main"); +@else engine.load(url); +@endif return app.exec(); } diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/tmpl.qbs b/share/qtcreator/templates/wizards/projects/qtquickapplication/tmpl.qbs index 3c5b8127cc9..050ace84150 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/tmpl.qbs +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/tmpl.qbs @@ -16,6 +16,6 @@ CppApplication { Group { Qt.core.resourcePrefix: "%{ProjectName}/" fileTags: ["qt.qml.qml", "qt.core.resource_data"] - files: ["main.qml"] + files: ["Main.qml"] } } diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json b/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json index 885a8487e31..88d63e19f9a 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json @@ -17,6 +17,10 @@ { "key": "MainCppFileName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src') }" }, { "key": "UseVirtualKeyboardByDefault", "value": "%{JS: value('Plugins').indexOf('Boot2Qt') >= 0 || value('Plugins').indexOf('Boot2QtQdb') >= 0 }" }, { "key": "TargetName", "value": "%{JS: 'app' + value('ProjectName') }" }, + { "key": "HasQSPSetup", "value": "%{JS: value('MinimumSupportedQtVersion') > '6.2' }"}, + { "key": "HasFailureSignal", "value": "%{JS: value('MinimumSupportedQtVersion') > '6.3' }"}, + { "key": "UsesAutoResourcePrefix", "value": "%{JS: value('MinimumSupportedQtVersion') > '6.4' && value('BuildSystem') === 'cmake' }"}, + { "key": "HasLoadFromModule", "value": "%{JS: value('MinimumSupportedQtVersion') > '6.4' && value('UsesAutoResourcePrefix') }"}, { "key": "QdsWizardPath", "value": "%{IDE:ResourcePath}/qmldesigner/studio_templates/projects" }, { "key": "QdsProjectStyle", "value": "%{JS: value('BuildSystem') === 'cmake' ? %{QdsProjectStyleInput} : false }" }, { "key": "NoQdsProjectStyle", "value": "%{JS: !%{QdsProjectStyle} }" }, @@ -104,6 +108,16 @@ { "checked": "%{UseVirtualKeyboardByDefault}" } + }, + { + "name": "MinimumSupportedQtVersion", + "trDisplayName": "The minimum version of Qt you want to build the application for", + "type": "ComboBox", + "data": + { + "items": [ "6.2", "6.4", "6.5" ], + "index": 1 + } } ] }, @@ -146,8 +160,8 @@ "condition": "%{NoQdsProjectStyle}" }, { - "source": "main.qml.tpl", - "target": "main.qml", + "source": "Main.qml.tpl", + "target": "Main.qml", "openInEditor": true, "condition": "%{NoQdsProjectStyle}" },