Commit 0fe0b133 authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen
Browse files

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: default avatarPeter Varga <pvarga@inf.u-szeged.hu>
Reviewed-by: default avatarKai Koehne <kai.koehne@qt.io>
Showing with 20 additions and 9 deletions
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
This lets the web view automatically scale on high-dpi displays. This lets the web view automatically scale on high-dpi displays.
Next, we instantiate a QApplication and a QWebEngineView. The URL 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. given a reasonable default size, and shown.
Finally, QApplication::exec() launches the main event loop. Finally, QApplication::exec() launches the main event loop.
......
...@@ -41,13 +41,23 @@ ...@@ -41,13 +41,23 @@
#include <QApplication> #include <QApplication>
#include <QWebEngineView> #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[]) int main(int argc, char *argv[])
{ {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv); QApplication app(argc, argv);
QWebEngineView view; QWebEngineView view;
view.setUrl(QUrl(QStringLiteral("http://www.qt.io"))); view.setUrl(commandLineUrlArgument());
view.resize(1024, 750); view.resize(1024, 750);
view.show(); view.show();
......
...@@ -44,12 +44,14 @@ ...@@ -44,12 +44,14 @@
#include <QApplication> #include <QApplication>
#include <QWebEngineSettings> #include <QWebEngineSettings>
QUrl getCommandLineUrlArgument() QUrl commandLineUrlArgument()
{ {
const QStringList args = QCoreApplication::arguments(); const QStringList args = QCoreApplication::arguments();
if (args.count() > 1) for (const QString &arg : args.mid(1)) {
return QUrl::fromUserInput(args.last()); if (!arg.startsWith(QLatin1Char('-')))
return QUrl(); return QUrl::fromUserInput(arg);
}
return QUrl(QStringLiteral("https://www.qt.io"));
} }
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -62,9 +64,7 @@ int main(int argc, char **argv) ...@@ -62,9 +64,7 @@ int main(int argc, char **argv)
QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true); QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
QUrl url = getCommandLineUrlArgument(); QUrl url = commandLineUrlArgument();
if (!url.isValid())
url = QStringLiteral("https://www.qt.io");
Browser browser; Browser browser;
BrowserWindow *window = browser.createWindow(); BrowserWindow *window = browser.createWindow();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment