summaryrefslogtreecommitdiff
path: root/examples/webkitwidgets/fancybrowser/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webkitwidgets/fancybrowser/main.cpp')
-rw-r--r--examples/webkitwidgets/fancybrowser/main.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/examples/webkitwidgets/fancybrowser/main.cpp b/examples/webkitwidgets/fancybrowser/main.cpp
index 451f247..bde31b0 100644
--- a/examples/webkitwidgets/fancybrowser/main.cpp
+++ b/examples/webkitwidgets/fancybrowser/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -41,15 +41,45 @@
#include <QtWidgets>
#include "mainwindow.h"
+static void showHelp(QCommandLineParser &parser, const QString errorMessage = QString())
+{
+ QString text;
+ QTextStream str(&text);
+ str << "<html><head/><body>";
+ if (!errorMessage.isEmpty())
+ str << "<p>" << errorMessage << "</p>";
+ str << "<pre>" << parser.helpText() << "</pre></body></html>";
+ QMessageBox box(errorMessage.isEmpty() ? QMessageBox::Information : QMessageBox::Warning,
+ QGuiApplication::applicationDisplayName(), text, QMessageBox::Ok);
+ box.setTextInteractionFlags(Qt::TextBrowserInteraction);
+ box.exec();
+}
+
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
+
+ QCommandLineParser commandLineParser;
+ commandLineParser.addPositionalArgument(QStringLiteral("url"),
+ QStringLiteral("The url to be loaded in the browser window."));
+ commandLineParser.process(app);
+ QStringList positionalArguments = commandLineParser.positionalArguments();
+
QUrl url;
- if (argc > 1)
- url = QUrl::fromUserInput(argv[1]);
+ if (positionalArguments.size() > 1) {
+ showHelp(commandLineParser, QStringLiteral("Too many arguments."));
+ return -1;
+ } else if (positionalArguments.size() == 1)
+ url = QUrl::fromUserInput(positionalArguments.at(0));
else
- url = QUrl("http://www.google.com/ncr");
- MainWindow *browser = new MainWindow(url);
- browser->show();
+ url = QUrl("http://www.qt-project.org");
+
+ if (!url.isValid()) {
+ showHelp(commandLineParser, QString("%1 is not a valid url.").arg(positionalArguments.at(0)));
+ return -1;
+ }
+
+ MainWindow browser(url);
+ browser.show();
return app.exec();
}