aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlscene/main.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-10-19 09:53:41 +0200
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-10-19 16:45:52 +0000
commit41dacccfbc53eeb0568a4d0bab766259abe26762 (patch)
treedf122ac518ce3b29fad29ec159737438e6459127 /tools/qmlscene/main.cpp
parentbb28b13d51648a51244e49e30426cd6ca9ac3e08 (diff)
qmlscene: Split argument parsing.
Loop over argv to filter out the arguments that need to be set before Q[Gui]Application creation and use QCoreApplication::arguments() for the remaining arguments. This prevents Qt's arguments (-geometry/-platform...) from interfering with the URL argument check. Change-Id: I2a88478534179b79578f7fb979a6b264a4fae44d Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Diffstat (limited to 'tools/qmlscene/main.cpp')
-rw-r--r--tools/qmlscene/main.cpp69
1 files changed, 38 insertions, 31 deletions
diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp
index ab37b6457d..9bf1c200e4 100644
--- a/tools/qmlscene/main.cpp
+++ b/tools/qmlscene/main.cpp
@@ -415,11 +415,11 @@ static void setWindowTitle(bool verbose, const QObject *topLevel, QWindow *windo
window->setTitle(newTitle);
}
-static QUrl parseUrlArgument(const char *arg)
+static QUrl parseUrlArgument(const QString &arg)
{
- const QUrl url = QUrl::fromUserInput(QFile::decodeName(arg), QDir::currentPath(), QUrl::AssumeLocalFile);
+ const QUrl url = QUrl::fromUserInput(arg, QDir::currentPath(), QUrl::AssumeLocalFile);
if (!url.isValid()) {
- fprintf(stderr, "Invalid URL: \"%s\"\n", arg);
+ fprintf(stderr, "Invalid URL: \"%s\"\n", qPrintable(arg));
return QUrl();
}
if (url.isLocalFile()) {
@@ -439,11 +439,39 @@ int main(int argc, char ** argv)
QStringList imports;
QStringList pluginPaths;
+
+ // Parse arguments for application attributes to be applied before Q[Gui]Application creation.
for (int i = 1; i < argc; ++i) {
- if (*argv[i] != '-') {
- options.url = parseUrlArgument(argv[i]);
+ const char *arg = argv[i];
+ if (!qstrcmp(arg, "--disable-context-sharing"))
+ options.applicationAttributes.removeAll(Qt::AA_ShareOpenGLContexts);
+ else if (!qstrcmp(arg, "--gles"))
+ options.applicationAttributes.append(Qt::AA_UseOpenGLES);
+ else if (!qstrcmp(arg, "--software"))
+ options.applicationAttributes.append(Qt::AA_UseSoftwareOpenGL);
+ else if (!qstrcmp(arg, "--desktop"))
+ options.applicationAttributes.append(Qt::AA_UseDesktopOpenGL);
+ else if (!qstrcmp(arg, "--no-scaling"))
+ options.applicationAttributes.append(Qt::AA_NoHighDpiScaling);
+ }
+
+ foreach (Qt::ApplicationAttribute a, options.applicationAttributes)
+ QCoreApplication::setAttribute(a);
+#ifdef QT_WIDGETS_LIB
+ QApplication app(argc, argv);
+#else
+ QGuiApplication app(argc, argv);
+#endif
+ app.setApplicationName("QtQmlViewer");
+ app.setOrganizationName("QtProject");
+ app.setOrganizationDomain("qt-project.org");
+
+ const QStringList arguments = QCoreApplication::arguments();
+ for (int i = 1, size = arguments.size(); i < size; ++i) {
+ if (!arguments.at(i).startsWith(QLatin1Char('-'))) {
+ options.url = parseUrlArgument(arguments.at(i));
} else {
- const QString lowerArgument = QString::fromLatin1(argv[i]).toLower();
+ const QString lowerArgument = arguments.at(i).toLower();
if (lowerArgument == QLatin1String("--maximized"))
options.maximized = true;
else if (lowerArgument == QLatin1String("--fullscreen"))
@@ -464,22 +492,12 @@ int main(int argc, char ** argv)
options.resizeViewToRootItem = true;
else if (lowerArgument == QLatin1String("--multisample"))
options.multisample = true;
- else if (lowerArgument == QLatin1String("--disable-context-sharing"))
- options.applicationAttributes.removeAll(Qt::AA_ShareOpenGLContexts);
- else if (lowerArgument == QLatin1String("--gles"))
- options.applicationAttributes.append(Qt::AA_UseOpenGLES);
- else if (lowerArgument == QLatin1String("--software"))
- options.applicationAttributes.append(Qt::AA_UseSoftwareOpenGL);
- else if (lowerArgument == QLatin1String("--desktop"))
- options.applicationAttributes.append(Qt::AA_UseDesktopOpenGL);
- else if (lowerArgument == QLatin1String("--no-scaling"))
- options.applicationAttributes.append(Qt::AA_NoHighDpiScaling);
else if (lowerArgument == QLatin1String("--verbose"))
options.verbose = true;
- else if (lowerArgument == QLatin1String("-i") && i + 1 < argc)
- imports.append(QString::fromLatin1(argv[++i]));
- else if (lowerArgument == QLatin1String("-p") && i + 1 < argc)
- pluginPaths.append(QString::fromLatin1(argv[++i]));
+ else if (lowerArgument == QLatin1String("-i") && i + 1 < size)
+ imports.append(arguments.at(++i));
+ else if (lowerArgument == QLatin1String("-p") && i + 1 < size)
+ pluginPaths.append(arguments.at(++i));
else if (lowerArgument == QLatin1String("--help")
|| lowerArgument == QLatin1String("-help")
|| lowerArgument == QLatin1String("--h")
@@ -488,17 +506,6 @@ int main(int argc, char ** argv)
}
}
- foreach (Qt::ApplicationAttribute a, options.applicationAttributes)
- QCoreApplication::setAttribute(a);
-#ifdef QT_WIDGETS_LIB
- QApplication app(argc, argv);
-#else
- QGuiApplication app(argc, argv);
-#endif
- app.setApplicationName("QtQmlViewer");
- app.setOrganizationName("QtProject");
- app.setOrganizationDomain("qt-project.org");
-
#ifndef QT_NO_TRANSLATION
QTranslator translator;
QTranslator qtTranslator;