diff options
author | Michael BrĂ¼ning <michael.bruning@digia.com> | 2014-04-07 14:06:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-14 06:46:36 +0200 |
commit | 5f0fbc683bce200b17fea82eb711d8ad4c2f3f23 (patch) | |
tree | e5096fa95f9b8dc38317349189f09441a4765ef9 /examples/webkitwidgets/fancybrowser/main.cpp | |
parent | 480cbb2b00b80baa90676fb3adfa982711006da8 (diff) | |
download | qtwebkit-examples-5.3.0.tar.gz |
Fix up Fancy Browser example.v5.3.0-rc1v5.3.0releasebaserock/v5.3.05.3.0
* Prevent leaking of MainWindow.
* Use proper command line argument parsing.
* Make the Qt project page the default page.
Task-number: QTBUG-38069
Change-Id: I6142ca207e659e47136e47e4d5817dfa617677e8
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
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(); } |