diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2016-03-11 10:00:33 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2016-03-11 17:06:54 +0000 |
commit | 99303e92ae9cf461f99b8eff8b37b42f758118b6 (patch) | |
tree | 7dd56787ed2e9ed711b599913bcb66e91e14b631 /examples/svg/svgviewer/main.cpp | |
parent | 86b82a0eea6c26fba34a9d2049935a18a088f3e7 (diff) | |
download | qtsvg-99303e92ae9cf461f99b8eff8b37b42f758118b6.tar.gz |
Polish the SVG viewer example.
- Use Qt 5 connection syntax, demonstrating lambdas.
- Use QCommandLineParser.
- Improve error handling.
- Use Mime API of QFileDialog, point to pictures location initially.
- Prevent the application from shrinking when loading small images.
- Minor polishing, status messages on loading, About Qt dialog.
Change-Id: I76f14001c9ab12cbfaaacc2ca4828b404e4b13b2
Reviewed-by: aavit <eirik.aavitsland@theqtcompany.com>
Diffstat (limited to 'examples/svg/svgviewer/main.cpp')
-rw-r--r-- | examples/svg/svgviewer/main.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/examples/svg/svgviewer/main.cpp b/examples/svg/svgviewer/main.cpp index 671262c..9155c87 100644 --- a/examples/svg/svgviewer/main.cpp +++ b/examples/svg/svgviewer/main.cpp @@ -39,7 +39,9 @@ ****************************************************************************/ #include <QApplication> -#include <QString> +#include <QCommandLineParser> +#include <QCommandLineOption> +#include <QStringList> #ifndef QT_NO_OPENGL #include <QGLFormat> #endif @@ -51,12 +53,21 @@ int main(int argc, char **argv) Q_INIT_RESOURCE(svgviewer); QApplication app(argc, argv); + QCoreApplication::setApplicationName("SVG Viewer"); + QGuiApplication::setApplicationDisplayName(QCoreApplication::applicationName()); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + + QCommandLineParser parser; + parser.setApplicationDescription("Qt SVG Viewer"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("file", "The file to open."); + parser.process(app); MainWindow window; - if (argc == 2) - window.openFile(argv[1]); - else - window.openFile(":/files/bubbles.svg"); + if (!window.loadFile(parser.positionalArguments().value(0, QLatin1String(":/files/bubbles.svg")))) + return -1; window.show(); return app.exec(); } |