diff options
author | Jani Heikkinen <jani.heikkinen@digia.com> | 2014-04-23 12:47:05 +0300 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@digia.com> | 2014-04-23 12:47:06 +0300 |
commit | bce5056b9e16a943357e362455a46685d3f22093 (patch) | |
tree | 73c4e6413605ede3edb556e929a13cb1cdf9e362 /examples/webkitwidgets/fancybrowser/main.cpp | |
parent | 184bfa548351bc82a74fc9323988a4a060fba738 (diff) | |
parent | 5f0fbc683bce200b17fea82eb711d8ad4c2f3f23 (diff) | |
download | qtwebkit-examples-stable.tar.gz |
Change-Id: Ic2230a86eb0dda83681f3d400367564ad7b594ad
Diffstat (limited to 'examples/webkitwidgets/fancybrowser/main.cpp')
-rw-r--r-- | examples/webkitwidgets/fancybrowser/main.cpp | 42 |
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(); } |