summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@theqtcompany.com>2016-05-09 11:01:18 +0200
committerAlexandru Croitor <alexandru.croitor@theqtcompany.com>2016-05-11 06:42:54 +0000
commitbdaea37070f420bea13a34081e56db1ee792d040 (patch)
treeba6d2dd9754d62581c9fb39fb11f76266129010d
parent272a1421076191e5653607fa06f8b96baeb1159a (diff)
[Simplebrowser] Fix command line option parsing.
Passing just command line options to Chromium prevents loading of the initial startup url. This happens because the startup url is overridden by the last command line argument, which happens to be a Chromium option, thus an invalid URL. Fix consists in using the last command line argument as the loading url only if it can be parsed as valid url. Change-Id: I3615ef57b6eddc5098de79cba1b1ba6b6af193ef Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--examples/webenginewidgets/simplebrowser/main.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/examples/webenginewidgets/simplebrowser/main.cpp b/examples/webenginewidgets/simplebrowser/main.cpp
index 761403fb..750e7ae4 100644
--- a/examples/webenginewidgets/simplebrowser/main.cpp
+++ b/examples/webenginewidgets/simplebrowser/main.cpp
@@ -42,6 +42,18 @@
#include "browserwindow.h"
#include <QApplication>
+QString getCommandLineUrlArgument()
+{
+ const QStringList args = QCoreApplication::arguments();
+ if (args.count() > 1) {
+ const QString lastArg = args.last();
+ const bool isValidUrl = QUrl::fromUserInput(lastArg).isValid();
+ if (isValidUrl)
+ return lastArg;
+ }
+ return QString();
+}
+
int main(int argc, char **argv)
{
QApplication app(argc, argv);
@@ -50,9 +62,9 @@ int main(int argc, char **argv)
BrowserWindow *window = new BrowserWindow();
Browser::instance().addWindow(window);
- QStringList args = QCoreApplication::arguments();
- if (args.count() > 1)
- window->loadPage(args.last());
+ const QString url = getCommandLineUrlArgument();
+ if (!url.isEmpty())
+ window->loadPage(url);
else
window->loadHomePage();