Sending external events to QtWebView components



  • All,
    Here is my requirement.

    1. My Qt WebKit applictaion loads the html page which has Html Buttons and javascript.
    2. An external event [comes from different process via sockets] should be captured and sent to this QtWebkit html page. Those events [JSON format] will be processed through Javascript and action will be taken in the html flow.
      Will it be possible using in QT? If so what is the approach [ classes i should look into]?

    And the screen display is controlled by different process and and user inputs [button clicks] will not be available to Qt webview directly. But they can be available to [x,y] coordinate to Qt application. If so, how these clicks can be processed inside the application.

    Please guide me the approach.

    Inotially i though of using Node.JS with websockets support where the external events [JSON] will be given to html loaded through QT. Unfortunately Node.JS and websockets support is not available, so i have do find different approach to receive the events from various processes.



  • You can capture data from socket by using "qtcpsocket":http://qt-project.org/doc/qt-5.1/qtnetwork/qtcpsocket.html class.

    There are two ways to interact with html page, which I know - sending events to it and executing javascript. Sending events approach suffers from scroll problem. It is desribed on that "page":http://stackoverflow.com/questions/2655414/qt-force-qwebview-to-click-on-a-web-element-even-one-not-visible-on-the-window in details. Executing javascript is a bit easier. For example, here is clicking on link function:

    @el.evaluateJavaScript("this.click()")@

    where el is QWebElement, which may be found by css selector.



  • Thanks,
    My further question is, if i have html page loaded through QtWebView
    and the html has something like this in javascript.

    var exampleSocket = new WebSocket("ws://www.example.com/socketserver", "protocolOne");

    Can Qtwebkit latest supports 'Websocket' and "ws://"?



  • Yes, Webkit supports web socket. If you are looking for examples : "start from this":https://gitorious.org/qtwebsocket

    EDIT : I think the above example does not support secure ws. Otherwise works fine. The Qt5 & Qt4 Port are slightly different.

    You can make use of the Bridge APIs, so that your c++ objects can be exposed to JS environment.


Log in to reply
 

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