set Qwebview url via js function
Unsolved
QML and Qt Quick
-
Hello all , i want to set the url of webview using javascript function . the function uses regex to get the url from a web page and then i want to provide that url to webview .
below is the code
import QtQuick 2.0 import QtWebView 1.1 Item { property string video function parsing() { var http = new XMLHttpRequest(); var url; http.onreadystatechange = function(){ /* checks if the request finished and response is ready ( readystate 4) 200: "OK" */ if(http.readyState == 4 && http.status == 200) { var content = http.responseText; url = content.match(/"http:\/\/www\.youtube\.com\/embed\/.+\"/); console.log(url); } video = url; console.log(video); }; http.open('GET',"http://someurl/"); http.send(); } WebView { id: webView anchors.fill: parent url: "set url here " } }
-
Use 'Component.onCompleted' handler to assign directly your url, or to call a function which will do that.
function setUrl(idOfWebView){
idOfWebView.url = "https://forum.qt.io"
}
WebView {
id: myWebView
anchors.fill: parent
// url: "set url here "Component.onCompleted : { /* any JavaScript function or expressions */ // myWebView.url = "https://forum.qt.io" ( DIRECT ) //or u can call a function like this : // setUrl(myWebView) // pass id of your webView to the function. ( FUNCTION ) } }
LA