Resuscitate the "legacy" Qt Quick Application wizard

Users still want to create new Qt Quick Application applications
targeting Qt 5 and with other build systems than cmake.

Fixes: QTCREATORBUG-28964
Change-Id: Ib87b7128f0b34eb4126ec771f324c70a960b2a03
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2023-04-21 11:30:18 +02:00
parent 440541da23
commit 1e02f6bf98
11 changed files with 566 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.16)
project(%{ProjectName} VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
qt_add_executable(%{TargetName}
main.cpp
)
qt_add_qml_module(%{TargetName}
URI %{ProjectName}
VERSION 1.0
QML_FILES main.qml %{AdditionalQmlFiles}
)
set_target_properties(%{TargetName} PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(%{TargetName}
PRIVATE Qt6::Quick)
install(TARGETS %{TargetName}
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

View File

@@ -0,0 +1,79 @@
cmake_minimum_required(VERSION 3.14)
project(%{ProjectName} VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@if %{HasTranslation}
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools)
set(TS_FILES %{TsFileName})
@else
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)
@endif
set(PROJECT_SOURCES
%{MainCppFileName}
qml.qrc
@if %{HasTranslation}
${TS_FILES}
@endif
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(%{ProjectName}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET %{ProjectName} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
@if %{HasTranslation}
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
@endif
else()
if(ANDROID)
add_library(%{ProjectName} SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(%{ProjectName}
${PROJECT_SOURCES}
)
endif()
@if %{HasTranslation}
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
@endif
endif()
target_link_libraries(%{ProjectName}
PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
set_target_properties(%{ProjectName} PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
install(TARGETS %{ProjectName}
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(QT_VERSION_MAJOR EQUAL 6)
qt_import_qml_plugins(%{ProjectName})
qt_finalize_executable(%{ProjectName})
endif()

View File

@@ -0,0 +1,40 @@
@if "%{UseVirtualKeyboard}" == "true"
QT += quick virtualkeyboard
@else
QT += quick
@endif
@if !%{IsQt6}
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
@endif
SOURCES += \\
%{MainCppFileName}
@if %{IsQt6}
resources.files = main.qml %{AdditionalQmlFiles}
resources.prefix = /$${TARGET}
RESOURCES += resources
@else
RESOURCES += qml.qrc
@endif
@if %{HasTranslation}
TRANSLATIONS += \\
%{TsFileName}
CONFIG += lrelease
CONFIG += embed_translations
@endif
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

View File

@@ -0,0 +1,48 @@
import qbs
CppApplication {
@if "%{UseVirtualKeyboard}" == "true"
Depends { name: "Qt"; submodules: ["quick", "virtualkeyboard"] }
@else
Depends { name: "Qt.quick" }
@endif
install: true
// Additional import path used to resolve QML modules in Qt Creator's code model
property pathList qmlImportPaths: []
@if !%{IsQt6}
cpp.defines: [
// You can make your code fail to compile if it uses deprecated APIs.
// In order to do so, uncomment the following line.
//"QT_DISABLE_DEPRECATED_BEFORE=0x060000" // disables all the APIs deprecated before Qt 6.0.0
]
@endif
files: [
"%{MainCppFileName}",
@if !%{IsQt6}
"main.qml",
"qml.qrc",
@endif
@if %{HasTranslation}
"%{TsFileName}",
@endif
]
@if %{HasTranslation}
Group {
fileTagsFilter: "qm"
Qt.core.resourcePrefix: "/i18n"
fileTags: "qt.core.resource_data"
}
@endif
@if %{IsQt6}
Group {
files: ["main.qml"%{AdditionalQmlFilesQbs}]
Qt.core.resourcePrefix: "%{ProjectName}/"
fileTags: ["qt.qml.qml", "qt.core.resource_data"]
}
@endif
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

View File

@@ -0,0 +1,48 @@
import QtQuick %{QtQuickVersion}
@if !%{IsQt6}
import QtQuick.Window %{QtQuickWindowVersion}
@endif
@if %{UseVirtualKeyboard}
import %{QtQuickVirtualKeyboardImport}
@endif
Window {
@if %{UseVirtualKeyboard}
id: window
@endif
width: 640
height: 480
visible: true
title: qsTr("Hello World")
@if %{UseVirtualKeyboard}
InputPanel {
id: inputPanel
z: 99
x: 0
y: window.height
width: window.width
states: State {
name: "visible"
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: window.height - inputPanel.height
}
}
transitions: Transition {
from: ""
to: "visible"
reversible: true
ParallelAnimation {
NumberAnimation {
properties: "y"
duration: 250
easing.type: Easing.InOutQuad
}
}
}
}
@endif
}

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,230 @@
{
"version": 1,
"supportedProjectTypes": [ "CMakeProjectManager.CMakeProject", "Qbs.QbsProject", "Qt4ProjectManager.Qt4Project" ],
"id": "V.QtQuickApplicationEmptyCompat",
"category": "D.ApplicationQt",
"trDescription": "Creates a Qt Quick application that contains an empty window.\n\nUse this \"compat\" version if you want to use other build systems than CMake or Qt versions lower than 6.",
"trDisplayName": "Qt Quick Application (compat)",
"trDisplayCategory": "Application (Qt)",
"icon": "icon.png",
"iconKind": "Themed",
"featuresRequired": [ "QtSupport.Wizards.FeatureQt.5.6" ],
"enabled": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0 || value('Plugins').indexOf('QbsProjectManager') >= 0 || value('Plugins').indexOf('CMakeProjectManager') >= 0}",
"options":
[
{ "key": "ProjectFile", "value": "%{JS: value('BuildSystem') === 'qmake' ? value('ProFile') : (value('BuildSystem') === 'cmake' ? value('CMakeFile') : value('QbsFile'))}" },
{ "key": "ProFile", "value": "%{JS: Util.fileName(value('ProjectDirectory') + '/' + value('ProjectName'), 'pro')}" },
{ "key": "QbsFile", "value": "%{JS: Util.fileName(value('ProjectDirectory') + '/' + value('ProjectName'), 'qbs')}" },
{ "key": "CMakeFile", "value": "%{ProjectDirectory}/CMakeLists.txt" },
{ "key": "IsQt6", "value": "%{JS: value('QtVersion').IsQt6}" },
{ "key": "MainCppFileName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src')}" },
{ "key": "QtQuickVersion", "value": "%{JS: value('QtVersion').QtQuickVersion}" },
{ "key": "QtQuickWindowVersion", "value": "%{JS: value('QtVersion').QtQuickWindowVersion}" },
{ "key": "QtQuickVirtualKeyboardImport", "value": "%{JS: value('QtVersion').QtQuickVirtualKeyboardImport}" },
{ "key": "QtQuickFeature", "value": "%{JS: (value('QtQuickVersion')=='') ? 'QtSupport.Wizards.FeatureQt.6.2' : 'QtSupport.Wizards.FeatureQtQuick.%{QtQuickVersion}'}" },
{ "key": "UseVirtualKeyboardByDefault", "value": "%{JS: value('Plugins').indexOf('Boot2Qt') >= 0 || value('Plugins').indexOf('Boot2QtQdb') >= 0}" },
{ "key": "HasTranslation", "value": "%{JS: value('TsFileName') !== ''}" },
{ "key": "SetQPAPhysicalSize", "value": "%{UseVirtualKeyboardByDefault}" },
{ "key": "AdditionalQmlFiles", "value": "" },
{ "key": "AdditionalQmlFilesQbs", "value": "" },
{ "key": "TargetName", "value": "%{JS: 'app' + value('ProjectName')}" }
],
"pages":
[
{
"trDisplayName": "Project Location",
"trShortTitle": "Location",
"typeId": "Project"
},
{
"trDisplayName": "Define Build System",
"trShortTitle": "Build System",
"typeId": "Fields",
"enabled": "%{JS: !value('IsSubproject')}",
"data":
[
{
"name": "BuildSystem",
"trDisplayName": "Build system:",
"type": "ComboBox",
"persistenceKey": "BuildSystemType",
"data":
{
"index": 1,
"items":
[
{
"trKey": "qmake",
"value": "qmake",
"condition": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}"
},
{
"trKey": "CMake",
"value": "cmake",
"condition": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}"
},
{
"trKey": "Qbs",
"value": "qbs",
"condition": "%{JS: value('Plugins').indexOf('QbsProjectManager') >= 0}"
}
]
}
}
]
},
{
"trDisplayName": "Define Project Details",
"trShortTitle": "Details",
"typeId": "Fields",
"data":
[
{
"name": "QtVersion",
"trDisplayName": "Minimum required Qt version:",
"type": "ComboBox",
"persistenceKey": "QtQuick.minimumQtVersion",
"data":
{
"index": 1,
"items":
[
{
"trKey": "Qt 6.2",
"value":
{
"QtQuickVersion": "",
"QtQuickWindowVersion": "",
"QtQuickVirtualKeyboardImport": "QtQuick.VirtualKeyboard",
"IsQt6": true
}
},
{
"trKey": "Qt 5.15",
"value":
{
"QtQuickVersion": "2.15",
"QtQuickWindowVersion": "2.15",
"QtQuickVirtualKeyboardImport": "QtQuick.VirtualKeyboard 2.15",
"IsQt6": false
}
},
{
"trKey": "Qt 5.14",
"value":
{
"QtQuickVersion": "2.14",
"QtQuickWindowVersion": "2.14",
"QtQuickVirtualKeyboardImport": "QtQuick.VirtualKeyboard 2.14",
"IsQt6": false
}
},
{
"trKey": "Qt 5.13",
"value":
{
"QtQuickVersion": "2.13",
"QtQuickWindowVersion": "2.13",
"QtQuickVirtualKeyboardImport": "QtQuick.VirtualKeyboard 2.4",
"IsQt6": false
}
},
{
"trKey": "Qt 5.12",
"value":
{
"QtQuickVersion": "2.12",
"QtQuickWindowVersion": "2.12",
"QtQuickVirtualKeyboardImport": "QtQuick.VirtualKeyboard 2.4",
"IsQt6": false
}
}
]
}
},
{
"name": "UseVirtualKeyboard",
"trDisplayName": "Use Qt Virtual Keyboard",
"type": "CheckBox",
"persistenceKey": "QtQuick.UseVirtualKeyboard.%{UseVirtualKeyboardByDefault}",
"data":
{
"checked": "%{UseVirtualKeyboardByDefault}"
}
}
]
},
{
"trDisplayName": "Translation File",
"trShortTitle": "Translation",
"typeId": "QtTranslation"
},
{
"trDisplayName": "Kit Selection",
"trShortTitle": "Kits",
"typeId": "Kits",
"enabled": "%{JS: !value('IsSubproject')}",
"data": {
"projectFilePath": "%{ProjectFile}",
"requiredFeatures": [ "QtSupport.Wizards.FeatureQt", "%{QtQuickFeature}" ]
}
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators":
[
{
"typeId": "File",
"data":
[
{
"source": "../app.pro",
"target": "%{ProFile}",
"openAsProject": true,
"condition": "%{JS: value('BuildSystem') === 'qmake'}"
},
{
"source": "%{JS: value('QtVersion').IsQt6 ? '../CMakeLists.6.x.txt' : '../CMakeLists.txt'}",
"target": "CMakeLists.txt",
"openAsProject": true,
"condition": "%{JS: value('BuildSystem') === 'cmake'}"
},
{
"source": "../app.qbs",
"target": "%{QbsFile}",
"openAsProject": true,
"condition": "%{JS: value('BuildSystem') === 'qbs'}"
},
{
"source": "../main.cpp",
"target": "%{MainCppFileName}"
},
{
"source": "main.qml.tpl",
"target": "main.qml",
"openInEditor": true
},
{
"source": "qml.qrc",
"condition": "%{JS: !value('QtVersion').IsQt6}"
},
{
"source": "../../translation.ts",
"target": "%{TsFileName}",
"condition": "%{HasTranslation}"
},
{
"source": "../../git.ignore",
"target": ".gitignore",
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
}
]
}
]
}

View File

@@ -0,0 +1,58 @@
%{Cpp:LicenseTemplate}\
%{JS: QtSupport.qtIncludes([], ["QtGui/QGuiApplication", "QtQml/QQmlApplicationEngine"])}
@if %{HasTranslation}
#include <QLocale>
#include <QTranslator>
@endif
int main(int argc, char *argv[])
{
@if %{UseVirtualKeyboard}
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
@endif
@if !%{IsQt6}
@if %{SetQPAPhysicalSize}
if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
}
@else
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
@endif
@endif
QGuiApplication app(argc, argv);
@if %{HasTranslation}
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "%{JS: value('ProjectName') + '_'}" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
app.installTranslator(&translator);
break;
}
}
@endif
QQmlApplicationEngine engine;
@if %{IsQt6}
const QUrl url(u"qrc:/%{JS: value('ProjectName')}/main.qml"_qs);
@else
const QUrl url(QStringLiteral("qrc:/main.qml"));
@endif
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}

View File

@@ -0,0 +1,25 @@
; This file can be edited to change the style of the application
; Read "Qt Quick Controls 2 Configuration File" for details:
; https://doc.qt.io/qt/qtquickcontrols2-configuration.html
@if '%{QtQuickControlsStyle}' != 'Default'
[Controls]
Style=%{QtQuickControlsStyle}
@if '%{QtQuickControlsStyle}' == 'Universal'
[Universal]
Theme=%{QtQuickControlsStyleTheme}
;Accent=Steel
;Foreground=Brown
;Background=Steel
@endif
@if '%{QtQuickControlsStyle}' == 'Material'
[Material]
Theme=%{QtQuickControlsStyleTheme}
;Accent=BlueGrey
;Primary=BlueGray
;Foreground=Brown
;Background=Grey
@endif
@endif