QML WebView confusion - can build/run WebView sample - cannot run with simple added QML



  • I am finding it very difficult to understand what you should or should not be doing in Qt 5.5/5.6 to use a WebView in your QML.

    The docs don't say anything about adding webview to your PRO file, yet the sample code has it added. The docs I read don't say anything about initializing the class, but the sample and the sample help file say you must.

    I can build the WebView sample and run it just fine (the minibrowser), but when I add webview to my *.pro file, and import QtWebKit 3.0 (or try with 1.0) it fails at runtime with "module "QtWebKit" is not installed."

    That suggests to me that there is some pathing issue to finding the QtWebKit and yet I can't find anything in the sample that references it and it's using the same kit.

    BTW, I read in the docs that you can't have QML types overlap with the web view - but I presume that means don't put QML on top of the webview as opposed to that meaning "the webview must be parented to the root object only."

    I've read that you should close QtCreator and restart it, you should clean your solution, run qmake again, then rebuild - I've tried those things. Same runtime error.

    Is this some sort of pathing issue? Again, the sample that shipped with Qt builds and runs fine, my sample that I created works fine with Qt (I've got all kinds of other QML working), but webview reports:

    QQmlApplicationEngine failed to load component
    qrc:/main.qml:3 module "QtWebKit" is not installed

    Is there some place I should be pointing my sample app that just happens to work with the Qt sample?

    Cheers


  • Lifetime Qt Champion

    Hi,

    For using QtWebKit web view you need to add QT += webkit to your .pro file.

    There are several modules that provide a web view:

    1. QtWebKit (deprecated)
    2. QtWebEngine (current)
    3. QtWebView (native web view for iOS, Android)


  • The minibrowser sample has:

    QT += qml quick webview

    I already have webview in my project's *.pro.

    When I add "webkit" I get the following error:

    ":-1: error: Unknown module(s) in QT: webkit"


  • Lifetime Qt Champion

    So you are looking at the qtwebview module ?



  • In case it helps, here's my complete PRO file:

    
    TEMPLATE = app
    
    QT += qml quick webview
    CONFIG += c++11
    
    SOURCES += main.cpp \
        mycode.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    
    HEADERS += \
        mycode.h
    


  • @SGaist I don't know what qtwebview maps to. I assume that's what "WebView" maps to, and is part of the import of QtWebKit 3.0 - no?

    I'm using the following in my very simple QML file:

    import QtQuick 2.5
    import QtQuick.Window 2.2
    import QtWebKit 3.0
    
    Window {
        id: mainWindow
        objectName: "mainWindow"
        visible: true
    
        // Default to 16:9
        width: 800
        height: 450
    
        // Prevent resizing
        minimumHeight: height
        minimumWidth: width
        maximumHeight: height
        maximumWidth: width
    
        function doSomething() {
            console.log( "inside DoSomething" );
        }
    
        Rectangle {
           id: testRect
           objectName: "testRect" // Needed for findChild() in C++
           anchors.fill: contentItem
           color: "black"
    
           WebView {
               id: webview
               url: "http://qt-project.org"
               anchors.fill: parent
           }
        }
    }
    


  • DOH - I was importing web kit, and not importing QtWebView (the only auto complete I was getting was for WebKit.)

    FIXED!

    @SGaist Thanks for the redirection :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.