Files
qt-creator/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp
Ulf Hermann cc9e5c3816 Wizards: Handle errors more elegantly in Qt Quick application template
By monitoring the objectCreated() signal of QQmlApplicationEngine we can
also catch errors if the components are instantiated asynchronously.

Task-number: QTBUG-39469
Change-Id: I796eb5561fc8d48ab5aa74d37b0964b118a1ba7e
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2019-01-18 09:46:27 +00:00

33 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
@if %{SetQPAPhysicalSize}
if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}
@else
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
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();
}