[Qtwebengine] Handle frames and web forms with QWebEngine

Allan Sandfeld Jensen allan.jensen at theqtcompany.com
Tue Feb 16 17:33:44 CET 2016


Even without modifying the html site, you can run javascript on it, using the 
QWebEnginePage::runJavaScript API. Just be aware that it is asynchronous, so 
you get the results as a callback.

We included an example of how to use qtwebchannel in Qt 5.6, check out the  
markdowneditor example. It basically boils down to this on the C++side:
    QWebChannel *channel = new QWebChannel(this);
    channel->registerObject(QStringLiteral("content"), &m_content);
    page->setWebChannel(channel);

And including qwebchannel.js on the JavaScript side. And then using code like 
this to get to the "content" object:
  new QWebChannel(qt.webChannelTransport,
    function(channel) {
      var content = channel.objects.content;
    }
  }


Using qtwebchannel on foreign content is harder, and until Qt 5.7 brings a 
security risk in that any objects you inject can be reached by the remote 
content too. The main difference to the markdowneditor example though is just 
that you need to inject qwebchannel.js using either runJavaScript on the new 
QWebEngineScript api. 

Best regards

On Tuesday 16 February 2016, NoRulez wrote:
> Since it isn't documented very well.
> Could you please give me a small example.
> 
> Best regards
> 
> > Am 16.02.2016 um 00:17 schrieb NoRulez <norulez at me.com>:
> > 
> > But i doesn't have access to modify the html site, I have only an url.
> > 
> > I don't know how to work with QWebChannel, since I'm not familiar with
> > JavaScript and I doesn't find out which function I can use from the
> > qwebchannel.js
> > 
> > Could you please help me?
> > Sorry but it was much easier with WebKit. :-(
> > 
> > Best Regards
> > 
> >>> Am 15.02.2016 um 22:10 schrieb Allan Sandfeld Jensen
> >>> <allan.jensen at theqtcompany.com>:
> >>> 
> >>> On Thursday 04 February 2016, NoRulez wrote:
> >>> Hello,
> >>> 
> >>> what is the preferred way to handle web forms (iterate over it like
> >>> QWebCollection does in QWebKit), search for frames by name and get
> >>> notified when a frame is created? (Was a signal in QWebKit)
> >>> 
> >>> Thanks in advance
> >> 
> >> I would suggest handling web-forms it in JavaScript. To get a signal
> >> from JavaScript, you should check out QtWebChannel, with that you can
> >> install QObjects in DOM then call any function from an event listener.
> >> 
> >> Best regards
> >> `Allan
> > 
> > _______________________________________________
> > QtWebEngine mailing list
> > QtWebEngine at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/qtwebengine


-- 
 
The Qt Company
Rudower Chausse 13, 12489 D-Berlin
 
The Qt Company is a group company of Digia Plc, 
Valimotie 21, FI-00380 Helsinki Finland



More information about the QtWebEngine mailing list