summaryrefslogtreecommitdiffstats
path: root/examples/pdf/singlepage/main.cpp
blob: be5c8f73c82ac8df3205c42f50cfc61193d226c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QQmlApplicationEngine>

#include <QGuiApplication>

#include <QCommandLineParser>
#include <QCommandLineOption>

int main(int argc, char* argv[])
{
    QCoreApplication::setApplicationName("Qt Quick PDF Viewer Example");
    QCoreApplication::setOrganizationName("QtProject");
    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:/singlepage/resources/test.pdf");
    if (!parser.positionalArguments().isEmpty())
        toLoad = QUrl::fromLocalFile(parser.positionalArguments().constFirst());

    engine.setInitialProperties({{"source", toLoad}});

    engine.load(QUrl(QStringLiteral("qrc:///singlepage/viewer.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}