Files
qt-creator/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp
Fabian Kosmale fa2ea6fd97 QtQuickApplication template: Support more modern API
(Re)add a way to select the minimum supported Qt version. If it is >=
6.4, connect to QQmlApplicationEngine::objectCreationFailed instead of
objectCreated, getting rid of the status check.
Moreover, if we have Qt >= 6.4, also use qt_standard_project_setup
instead of manually enabling AUTOMOC. That is available since 6.3, but
no need to clutter the version selection list with too many entries.
If only 6.5 or higher is required, put the QML files under
AUTO_RESOURCE_PREFIX, and use loadFromModule instead of load.
Unconditionally rename  main.qml to Main.qml, which is necessary for
loadFromModule to work, and making this conditional on the used Qt
version is more trouble than it is worth.

For qbs, we do not yet put the files under the auto resource prefix, so
do not use loadFromModule there.

Fixes: QTBUG-47996
Change-Id: Ib8ca375c2316b58eecf54009d36fc9f7dac7c1f4
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2023-01-31 06:38:19 +00:00

35 lines
1.0 KiB
C++

%{Cpp:LicenseTemplate}\
%{JS: QtSupport.qtIncludes([], ["QtGui/QGuiApplication", "QtQml/QQmlApplicationEngine"])}
int main(int argc, char *argv[])
{
@if %{UseVirtualKeyboard}
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
@endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
@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();
}