Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. set Qwebview url via js function
Forum Updated to NodeBB v4.3 + New Features

set Qwebview url via js function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qwebview qquickwebviewqml + js
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qjay
    wrote on 3 Aug 2017, 16:05 last edited by Qjay 8 Mar 2017, 16:21
    #1

    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 "
    
        }
    }
    
    
    1 Reply Last reply
    0
    • O Offline
      O Offline
      ODБOï
      wrote on 10 Aug 2017, 09:01 last edited by ODБOï 8 Oct 2017, 09:02
      #2

      Hi,
      [...]
      video = url;
      console.log(video);
      webView.url = video //webView is 'id' of your WebView{}
      [...]
      LA

      Q 1 Reply Last reply 10 Aug 2017, 12:15
      0
      • O ODБOï
        10 Aug 2017, 09:01

        Hi,
        [...]
        video = url;
        console.log(video);
        webView.url = video //webView is 'id' of your WebView{}
        [...]
        LA

        Q Offline
        Q Offline
        Qjay
        wrote on 10 Aug 2017, 12:15 last edited by
        #3

        @LeLev hey , how can i auto call the parsing() function i.e. when i load this qml the function should automatically get executed !!

        1 Reply Last reply
        0
        • O Offline
          O Offline
          ODБOï
          wrote on 10 Aug 2017, 12:40 last edited by ODБOï 8 Oct 2017, 12:41
          #4

          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

          1 Reply Last reply
          0

          3/4

          10 Aug 2017, 12:15

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved