Using Qt Webview 1.1 with Qt WebChannel



  • Hi,

    Can we use Qt Webview 1.1 with Qt WebChannel in order to maintain the QML elements/ objects form HTML file in the Qt Webview?

    I want to develop a mobile hybrid app by using QtWebview.

    Regards



  • Yes, you can, using WebSockets as a transport. But not with QML only - some C++ code is required.

    1. Implement a transport using QWebChannelAbstractTransport and register it at QML side;
    2. Add WebChannel;
    3. Add WebSocketServer;
    4. Connect your channel to the transport at onClientConnected:
    WebSocketServer {
        listen: true
        port: 55222
        onClientConnected: {
            if(webSocket.status === WebSocket.Open) {
                channel.connectTo(transport)
                webSocket.onTextMessageReceived.connect(transport.textMessageReceive)
                transport.onMessageChanged.connect(webSocket.sendTextMessage)
            }
        }
    }
    

Log in to reply
 

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