|
| 1 | +#include <QCommandLineParser> |
| 2 | +#include <QFile> |
| 3 | +#include <QGuiApplication> |
| 4 | +#include <QQmlApplicationEngine> |
| 5 | + |
| 6 | +int main(int argc, char *argv[]) |
| 7 | +{ |
| 8 | + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
| 9 | + |
| 10 | + QGuiApplication app(argc, argv); |
| 11 | + app.setOrganizationName("machinekoder.com"); |
| 12 | + app.setOrganizationDomain("machinekoder.com"); |
| 13 | + app.setApplicationName("LiveCodingExample"); |
| 14 | + app.setApplicationDisplayName("Live Coding Example"); |
| 15 | + |
| 16 | + QCommandLineParser parser; |
| 17 | + parser.setApplicationDescription("Live Coding Example"); |
| 18 | + parser.addHelpOption(); |
| 19 | +#ifdef QT_DEBUG |
| 20 | + QCommandLineOption forceOption(QStringList() << "l" << "live", |
| 21 | + QCoreApplication::translate("live", "Start live coding mode.")); |
| 22 | + parser.addOption(forceOption); |
| 23 | +#endif |
| 24 | + parser.process(app); |
| 25 | + |
| 26 | + QString fileName = QStringLiteral("main.qml"); |
| 27 | +#ifdef QT_DEBUG |
| 28 | + if (parser.isSet(forceOption)) { |
| 29 | + fileName = QStringLiteral("live.qml"); |
| 30 | + } |
| 31 | +#endif |
| 32 | + |
| 33 | + QQmlApplicationEngine engine; |
| 34 | + engine.addImportPath(QStringLiteral(".")); |
| 35 | + engine.addImportPath(QStringLiteral("qrc:/")); |
| 36 | + QFile file(QStringLiteral("./") + fileName); |
| 37 | + if (file.exists()) { |
| 38 | + engine.load(QStringLiteral("./") + fileName); |
| 39 | + } |
| 40 | + else { |
| 41 | + engine.load(QUrl(QStringLiteral("qrc:/") + fileName)); |
| 42 | + } |
| 43 | + if (engine.rootObjects().isEmpty()) |
| 44 | + return -1; |
| 45 | + |
| 46 | + return app.exec(); |
| 47 | +} |
0 commit comments