Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a way I can display a local webpage inside of qml?
Forum Updated to NodeBB v4.3 + New Features

Is there a way I can display a local webpage inside of qml?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 6.0k Views
  • 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.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by
    #1

    I'm trying to display a local html page inside a qml page, I googled and it says that I have to create a widget and display the html page inside of the widget, but that's kind of strange, so is there a way I can display local html page inside the qml window? thank you

    Mandruk1331

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      Hi @mandruk1331

      which version of qt do you have?

      in Qt 5 you can use WebView QML object it is possible

      you can read doc here:

      http://doc.qt.io/qt-5/qml-qtwebview-webview.html

      there is also an example in qt examples,

      example:

      import QtQuick 2.0
      import QtQuick.Controls 1.0
      import QtWebKit 3.0
      
      ScrollView {
          width: 1280
          height: 720
          WebView {
              id: webview
              url: "path to your html local file"
              anchors.fill: parent
              onNavigationRequested: {
                  // detect URL scheme prefix, most likely an external link
                  var schemaRE = /^\w+:/;
                  if (schemaRE.test(request.url)) {
                      request.action = WebView.AcceptRequest;
                  } else {
                      request.action = WebView.IgnoreRequest;
                      // delegate request.url here
                  }
              }
          }
      }
      

      I just tried to put a link of one html local file like this :

      url: file:///home/user/Desktop/your_html_file.html

      and it worked without any problem ,

      Hope this can help

      mandruk1331M 1 Reply Last reply
      5
      • M mostefa

        Hi @mandruk1331

        which version of qt do you have?

        in Qt 5 you can use WebView QML object it is possible

        you can read doc here:

        http://doc.qt.io/qt-5/qml-qtwebview-webview.html

        there is also an example in qt examples,

        example:

        import QtQuick 2.0
        import QtQuick.Controls 1.0
        import QtWebKit 3.0
        
        ScrollView {
            width: 1280
            height: 720
            WebView {
                id: webview
                url: "path to your html local file"
                anchors.fill: parent
                onNavigationRequested: {
                    // detect URL scheme prefix, most likely an external link
                    var schemaRE = /^\w+:/;
                    if (schemaRE.test(request.url)) {
                        request.action = WebView.AcceptRequest;
                    } else {
                        request.action = WebView.IgnoreRequest;
                        // delegate request.url here
                    }
                }
            }
        }
        

        I just tried to put a link of one html local file like this :

        url: file:///home/user/Desktop/your_html_file.html

        and it worked without any problem ,

        Hope this can help

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on last edited by
        #3

        @mostefa said in Is there a way I can display a local webpage inside of qml?:

        file:///

        OMG I have seen that one) It works, thank you very much. The problem was that i did not add the 'file:///' string. Thank you!

        Mandruk1331

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mostefa
          wrote on last edited by mostefa
          #4

          @mandruk1331

          Glad to see that this helped you, but instead of calling local file like we did, i advise you to put your html in qt ressource system

          and then just write url: "yourhtmlfile" instead of url :"file///......"

          it is better !

          mandruk1331M 1 Reply Last reply
          2
          • M mostefa

            @mandruk1331

            Glad to see that this helped you, but instead of calling local file like we did, i advise you to put your html in qt ressource system

            and then just write url: "yourhtmlfile" instead of url :"file///......"

            it is better !

            mandruk1331M Offline
            mandruk1331M Offline
            mandruk1331
            wrote on last edited by
            #5

            @mostefa Ok:-)

            Mandruk1331

            1 Reply Last reply
            0

            • Login

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