QWebEngine: Handling receive and send requests when executing runJavaScript

I am looking for a way to handle receive and send requests executed when running java script code after loading a website. Here's the description: url can be loaded via QWebEnginePage :: load and there are some buttons on the page with javescript events bound to them. the buttons do some of the receive and send requests from the internet. Is there anyway that I could signal my classes when get and post requests are executed by these javascript events. If this is not possible with QWebEngine, what are the other Qt options to complete the job. I am looking for some options that would not be absolute in the future as they are part of a long term project. Thanks to

+3


source to share


1 answer


You can use QWebChannel which should work in your case.

CPP file

QWebChannel* webChannel = new QWebChannel();
webChannel->registerObject("foo", this);
webview->page()->setWebChannel(webChannel);

      



in HTML file

<script type="text/javascript" src="qrc:/Map/qwebchannel.js"></script>
<script type="text/javascript">
    new QWebChannel(qt.webChannelTransport, function(channel) {
    // all published objects are available in channel.objects under
    // the identifier set in their attached WebChannel.id property
    var foo = channel.objects.foo;

    // access a property
    alert(foo.hello);

    // connect to a signal
    foo.someSignal.connect(function(message) {
       alert("Got signal: " + message);
    });

   // invoke a method, and receive the return value asynchronously
   foo.someMethod("bar", function(ret) {
       alert("Got return value: " + ret);
   });
});
</script>

      

0


source







All Articles