From 671b8e79215e8d84becb508457586c7eebb229f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 1 Sep 2014 11:12:10 +0200 Subject: Document QUrl usage behavior. Document that QUrls are used as-is and that QUrl::fromUserInput should be called when appropriate. Update the example to call QUrl::fromUserInput via a helper class. This is a workaround until QtQuick provides a fromUserInput function. Change-Id: I51f521126e50ee4d9b0223ef11f32d5576be10a8 Reviewed-by: Christian Stromme --- examples/webview/webview/main.cpp | 13 +++++++++++++ examples/webview/webview/main.qml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'examples/webview') diff --git a/examples/webview/webview/main.cpp b/examples/webview/webview/main.cpp index 8525bc2..b569129 100644 --- a/examples/webview/webview/main.cpp +++ b/examples/webview/webview/main.cpp @@ -38,14 +38,27 @@ ** ****************************************************************************/ +#include #include #include +#include + +// Workaround: As of Qt 5.4 QtQuick does not expose QUrl::fromUserInput. +class Utils : public QObject { + Q_OBJECT +public: + Utils(QObject* parent = 0) : QObject(parent) { } + Q_INVOKABLE static QUrl fromUserInput(const QString& userInput) { return QUrl::fromUserInput(userInput); } +}; + +#include "main.moc" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("utils", new Utils(&engine)); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); diff --git a/examples/webview/webview/main.qml b/examples/webview/webview/main.qml index 5b1e951..57b3e7a 100644 --- a/examples/webview/webview/main.qml +++ b/examples/webview/webview/main.qml @@ -75,7 +75,7 @@ ApplicationWindow { anchors.margins: topLevel.width / 30 text: qsTr("Go") onClicked: { - webView.url = addressField.text + webView.url = utils.fromUserInput(addressField.text) } } -- cgit v1.2.3