summaryrefslogtreecommitdiffstats
path: root/examples/webview
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2014-09-01 11:12:10 +0200
committerMorten Johan Sørvig <morten.sorvig@digia.com>2014-09-01 12:46:36 +0200
commit671b8e79215e8d84becb508457586c7eebb229f6 (patch)
treeb6ff397ef9b3509142b4884aa73f6f123a4e91f4 /examples/webview
parentdb296742485bb81d684b21ad6712f4af341fc9ec (diff)
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 <christian.stromme@digia.com>
Diffstat (limited to 'examples/webview')
-rw-r--r--examples/webview/webview/main.cpp13
-rw-r--r--examples/webview/webview/main.qml2
2 files changed, 14 insertions, 1 deletions
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 <QtCore/QUrl>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
+#include <QtQml/QQmlContext>
+
+// 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)
}
}