QWebFrame and QWebElementCollection equivalences?



  • Hello,

    I'm currently porting a dictionary app (GoldenDict to be precise) from QtWebKit to QtWebEngine. That app used QWebFrame and QWebElementCollection for which I couldn't find equivalences.

    1. QWebFrame

    I read from QtWebEngine docs:

    In Qt WebEngine, frame handling has been merged into the QWebEnginePage class. All child frames are now considered part of the content, and only accessible through JavaScript.
    

    That means iframe elements could only be manipulated via JavaScript. But it seems QtWebKit have exposed this functionality via C++ API, which I think is far more convenient to use.

    Yet, I found this snippet from Qt 5.9.2's example demobrowser:

    #if defined(QWEBENGINEPAGE_UNSUPPORTEDCONTENT)
    // ...
    QList<QWebEngineFrame*> frames;
    frames.append(mainFrame());
    // ...
    #endif
    

    QWebEngineFrame is actually not implemented in QtWebEngine, and QWEBENGINEPAGE_UNSUPPORTEDCONTENT is not defined in that example project either. Does it means QWebEngineFrame is planned to be added into QtWebEngine in future releases?

    1. QWebElementCollection

    To me, QWebElementCollection looks very like that it's a DOM model with C++ API, you use it to iterate through the DOM tree and get what you want, so sweat!

    But I couldn't do that in QtWebEngine, am I right?

    To summarise, I had a feeling that with QtWebKit, you have fine granule control over individual elements of a web page. But with QtWebEngine, most functionalities were packaged into the underlying Chromium foundation, and you have to rely on JavaScript a lot, which is a burden for me as a C++ programmer who is not so familiar with JavaScript.

    And that made me come up with a third question:

    1. If I have to manipulate HTML elements with JavaScript, how do I transfer results back to C++? Such as iterate through some group of elements and query for some attributes?

    I'd apologize if I didn't compose those questions well, since I've just started to use QtWebEngine or QtWebkit very recently. Hope you would forgive me. And thank you for any help.


  • Moderators

    @victl said in QWebFrame and QWebElementCollection equivalences?:

    If I have to manipulate HTML elements with JavaScript, how do I transfer results back to C++? Such as iterate through some group of elements and query for some attributes?

    yes, DOM manipulation like with QWebElement is now only possible via JavaScript.

    See this example. Communication between C++ and JavaScript is supported via the QtWebChannel module. Not as powerful as QWebElement API was, but better than nothing.
    You need to inject a qwebchannel.js into the web-page though.
    See this for automatic injection into every QtWebEngine page.


  • Lifetime Qt Champion

    Hi,

    Just in case, did you consider @Konstantin-Tokarev QtWebKit reboot project ?



  • @SGaist Yes I have tried the new QtWebKit module. It all works very well. I'm looking forward to see QtWebKit 2.0 revive in future Qt releases.


Log in to reply
 

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