summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-25 16:27:00 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-28 15:16:45 +0000
commit0fe0b133b7410940fcba89539d512a7bc13df979 (patch)
tree5719e4094ae2147f0c452f34d74875ae6b93a6e3
parentec37477bf8a9f8f2591670f04c9e21c697d7e4e4 (diff)
Change the minimal example to be minimally useful
Open the first non-flag argument if one is given Fixes up simplebrowser to act similarly Change-Id: I40270a0f7bc06ce52117f23f7ccbdd743d3d97f6 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r--examples/webenginewidgets/minimal/doc/src/minimal.qdoc3
-rw-r--r--examples/webenginewidgets/minimal/main.cpp12
-rw-r--r--examples/webenginewidgets/simplebrowser/main.cpp14
3 files changed, 20 insertions, 9 deletions
diff --git a/examples/webenginewidgets/minimal/doc/src/minimal.qdoc b/examples/webenginewidgets/minimal/doc/src/minimal.qdoc
index dd6a7056..c566c55d 100644
--- a/examples/webenginewidgets/minimal/doc/src/minimal.qdoc
+++ b/examples/webenginewidgets/minimal/doc/src/minimal.qdoc
@@ -46,7 +46,8 @@
This lets the web view automatically scale on high-dpi displays.
Next, we instantiate a QApplication and a QWebEngineView. The URL
- to load is set by calling \l QWebEngineView::setUrl. The view widget is
+ to load is taken from the command-line in \l commandLineUrlArgument and
+ loaded by calling \l QWebEngineView::setUrl. The view widget is
given a reasonable default size, and shown.
Finally, QApplication::exec() launches the main event loop.
diff --git a/examples/webenginewidgets/minimal/main.cpp b/examples/webenginewidgets/minimal/main.cpp
index 729d68fa..cff489c7 100644
--- a/examples/webenginewidgets/minimal/main.cpp
+++ b/examples/webenginewidgets/minimal/main.cpp
@@ -41,13 +41,23 @@
#include <QApplication>
#include <QWebEngineView>
+QUrl commandLineUrlArgument()
+{
+ const QStringList args = QCoreApplication::arguments();
+ for (const QString &arg : args.mid(1)) {
+ if (!arg.startsWith(QLatin1Char('-')))
+ return QUrl::fromUserInput(arg);
+ }
+ return QUrl(QStringLiteral("https://www.qt.io"));
+}
+
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
- view.setUrl(QUrl(QStringLiteral("http://www.qt.io")));
+ view.setUrl(commandLineUrlArgument());
view.resize(1024, 750);
view.show();
diff --git a/examples/webenginewidgets/simplebrowser/main.cpp b/examples/webenginewidgets/simplebrowser/main.cpp
index 93dfc8a8..25eb15f8 100644
--- a/examples/webenginewidgets/simplebrowser/main.cpp
+++ b/examples/webenginewidgets/simplebrowser/main.cpp
@@ -44,12 +44,14 @@
#include <QApplication>
#include <QWebEngineSettings>
-QUrl getCommandLineUrlArgument()
+QUrl commandLineUrlArgument()
{
const QStringList args = QCoreApplication::arguments();
- if (args.count() > 1)
- return QUrl::fromUserInput(args.last());
- return QUrl();
+ for (const QString &arg : args.mid(1)) {
+ if (!arg.startsWith(QLatin1Char('-')))
+ return QUrl::fromUserInput(arg);
+ }
+ return QUrl(QStringLiteral("https://www.qt.io"));
}
int main(int argc, char **argv)
@@ -62,9 +64,7 @@ int main(int argc, char **argv)
QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
- QUrl url = getCommandLineUrlArgument();
- if (!url.isValid())
- url = QStringLiteral("https://www.qt.io");
+ QUrl url = commandLineUrlArgument();
Browser browser;
BrowserWindow *window = browser.createWindow();