3

I am looking for possibility of handling get and post requests made by running a java-script code after a website is loaded. Here is the description: a url could be loaded via QWebEnginePage::load and the page contains some buttons with javescript events bind to them. buttons do some get and post requests from internet. Is there anyway that I could signal my classes when the get and post requests are performed by that javascript events. If it is impossible with QWebEngine What are the other options in Qt to do job. I am looking for some options that would not be absolute in the future since it is part of long-term project. Thanks

AMCoded
  • 1,374
  • 2
  • 24
  • 39
  • You mean something like this? http://stackoverflow.com/questions/14342220/invoke-c-method-from-webviews-javascript – Macias May 06 '17 at 01:25
  • I don't think so, for example in a submission form there are special buttons using java-script to retriever special information via get method while you are filling the form. I want my class to be signaled when such a request is performed with a java-script. – AMCoded May 08 '17 at 16:21

1 Answers1

0

You can use QWebChannel that 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>
SourabhKus
  • 818
  • 8
  • 23