diff options
author | Andre de la Rocha <andre.rocha@qt.io> | 2017-10-25 15:35:30 +0200 |
---|---|---|
committer | Andre de la Rocha <andre.rocha@qt.io> | 2017-11-01 18:17:53 +0000 |
commit | 17bdee86da84c6718fc1bbe8cedf5bdf07240837 (patch) | |
tree | 1dd0d9595a3e83e03ea3447cc265146f164dfffb /examples/winextras/quickplayer/main.cpp | |
parent | 07f6d25a00af112d46e939992fb9cf42879fc7c1 (diff) |
Revamp Qt Windows Extras examples
Use nullptr, member initialization, new connect syntax, QStringLiteral, etc.
Change-Id: I1404701fcc227f8133bc22548ea1cee02eab4ed9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Michael Winkelmann <michael.winkelmann@qt.io>
Diffstat (limited to 'examples/winextras/quickplayer/main.cpp')
-rw-r--r-- | examples/winextras/quickplayer/main.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/examples/winextras/quickplayer/main.cpp b/examples/winextras/quickplayer/main.cpp index 9faa390..479444f 100644 --- a/examples/winextras/quickplayer/main.cpp +++ b/examples/winextras/quickplayer/main.cpp @@ -40,6 +40,8 @@ #include <QQmlApplicationEngine> #include <QGuiApplication> +#include <QCommandLineParser> +#include <QCommandLineOption> #include <QWindow> #include <QQmlContext> #include <QStandardPaths> @@ -47,21 +49,32 @@ int main(int argc, char *argv[]) { + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); - app.setApplicationName("QuickPlayer"); - app.setOrganizationName("QtWinExtras"); - app.setOrganizationDomain("qt-project.org"); - app.setApplicationDisplayName("QtWinExtras Quick Player"); + QCoreApplication::setApplicationName(QStringLiteral("QuickPlayer")); + QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); + QCoreApplication::setOrganizationName(QStringLiteral("QtWinExtras")); + QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); + QGuiApplication::setApplicationDisplayName(QStringLiteral("QtWinExtras Quick Player")); QQmlApplicationEngine engine; const QStringList musicPaths = QStandardPaths::standardLocations(QStandardPaths::MusicLocation); const QUrl musicUrl = QUrl::fromLocalFile(musicPaths.isEmpty() ? QDir::homePath() : musicPaths.first()); engine.rootContext()->setContextProperty(QStringLiteral("musicUrl"), musicUrl); - const QStringList arguments = QCoreApplication::arguments(); - const QUrl commandLineUrl = arguments.size() > 1 ? QUrl::fromLocalFile(arguments.at(1)) : QUrl(); + + QCommandLineParser parser; + parser.setApplicationDescription(QGuiApplication::applicationDisplayName()); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument(QStringLiteral("url"), QStringLiteral("The URL to open.")); + parser.process(app); + QUrl commandLineUrl; + if (!parser.positionalArguments().isEmpty()) + commandLineUrl = QUrl::fromUserInput(parser.positionalArguments().constFirst(), QDir::currentPath(), QUrl::AssumeLocalFile); engine.rootContext()->setContextProperty(QStringLiteral("url"), commandLineUrl); - engine.load(QUrl("qrc:/main.qml")); - QObject* root = engine.rootObjects().value(0); + + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + QObject *root = engine.rootObjects().value(0); if (QWindow *window = qobject_cast<QWindow *>(root)) window->show(); else |