summaryrefslogtreecommitdiffstats
path: root/examples/pdf/pdfviewer/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pdf/pdfviewer/main.cpp')
-rw-r--r--examples/pdf/pdfviewer/main.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/examples/pdf/pdfviewer/main.cpp b/examples/pdf/pdfviewer/main.cpp
index da940dd3f..bed0e5860 100644
--- a/examples/pdf/pdfviewer/main.cpp
+++ b/examples/pdf/pdfviewer/main.cpp
@@ -1,9 +1,13 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QGuiApplication>
#include <QQmlApplicationEngine>
+#include <QGuiApplication>
+
+#include <QCommandLineParser>
+#include <QCommandLineOption>
+
int main(int argc, char* argv[])
{
QCoreApplication::setApplicationName("Qt Quick PDF Viewer Example");
@@ -11,14 +15,23 @@ int main(int argc, char* argv[])
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
QGuiApplication app(argc, argv);
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("file", "The file to open.");
+ parser.process(app);
+
QQmlApplicationEngine engine;
+
+ QUrl toLoad = QUrl("qrc:/pdfviewer/resources/test.pdf");
+ if (!parser.positionalArguments().isEmpty())
+ toLoad = QUrl::fromLocalFile(parser.positionalArguments().constFirst());
+
+ engine.setInitialProperties({{"source", toLoad}});
+
engine.load(QUrl(QStringLiteral("qrc:///pdfviewer/viewer.qml")));
- if (app.arguments().count() > 1) {
- QUrl toLoad = QUrl::fromUserInput(app.arguments().at(1));
- engine.rootObjects().first()->setProperty("source", toLoad);
- } else {
- engine.rootObjects().first()->setProperty("source", QStringLiteral("resources/test.pdf"));
- }
+ if (engine.rootObjects().isEmpty())
+ return -1;
return app.exec();
}