Files
qt-creator/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp

45 lines
1.4 KiB
C++
Raw Normal View History

%{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 mainQml(QStringLiteral("qrc:/main.qml"));
// Catch the objectCreated signal, so that we can determine if the root component was loaded
// successfully. If not, then the object created from it will be null. The root component may
// get loaded asynchronously.
const QMetaObject::Connection connection = QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated,
&app, [&](QObject *object, const QUrl &url) {
if (url != mainQml)
return;
if (!object)
app.exit(-1);
else
QObject::disconnect(connection);
}, Qt::QueuedConnection);
engine.load(mainQml);
return app.exec();
}