Nominate our 2022 Qt Champions!

QtQuick and QWebFrame::toPlainText()

  • Is there a QtQuick equivalent to the C++ QWebFrame::toPlainText() method?

    I am able to connect and display a URL page that is plain text using a QML WebView element but I have not found a way to get that content into a string variable. There is no available method or function of the WebView element that will return the text of the content as plain text.

    I considered using document.getElementById in a Javascript function but a text document does not have HTML elements necessarily.

    I need to get whatever the text is - whether it is HTML, Javascript, or plain text. Can anyone help?

  • OK since I posted this I have tried several things - none of which even come close. However I did find an obscure post on the Nokia forum which I think may be the solution (

    I have constructed a C++ header in this manner:

    #ifndef WWVSOURCE_H
    #define WWVSOURCE_H

    #include <QtCore/QUrl>
    #include <QtCore/QObject>
    #include <QtCore/QString>
    #include <QtCore/QStringList>
    #include <QtGui/QWidget>
    #include <QtWebKit/QWebView>
    #include <QtWebKit/QWebFrame>

    class URLSource : public QObject

    URLSource(QObject *parent = 0) : QObject(parent) { }

    Q_INVOKABLE void getURL(const QString &intext)
    QWebView *webWWV = new QWebView;
    QWebFrame *mainFrame = webWWV->page()->mainFrame();
    instr = mainFrame->toPlainText();

    Q_INVOKABLE int getValue()
    . . . ;
    return s;

    And additions to my QML project like this:
    function updateUI() {
    myobject.invalue = URLSource.getValue();

    Component.onCompleted: {
        // collect text and parse values to plug into meters


    The only problem is that there is undefined reference errors in the compile that I am unable to resolve. The output is :

    debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0x25): undefined reference to _imp___ZN8QWebViewC1EP7QWidget' debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0x50): undefined reference to_imp___ZN8QWebView6setUrlERK4QUrl'
    debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0x84): undefined reference to _imp___ZNK8QWebView4pageEv' debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0x8e): undefined reference to_imp___ZNK8QWebPage9mainFrameEv'
    debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0xa5): undefined reference to `_imp___ZNK9QWebFrame11toPlainTextEv'
    collect2: ld returned 1 exit status

    I have all the includes for QString, QWebView, QWebFrame, QStringList and QUrl in the header. I have cleaned the project and run the QMake several times with no change.

    Anyone have a clue?


    Well this method does seem to work. I discovered I needed to add an a context to the main.cpp like the reference did and and import to Qt 4.7 to the qml in my viewer module to get rid of the errors.

    The problem now is that I am having difficulty getting QML to recognize the Qt object set up in the viewer.setContext() statement in main.
    I have added enough debug code to know that the Qt C++ code is called at least once and the URL is downloaded to a string. But none of the public members exposed (including the string mentioned) are accessible after that.

    I am surprised that some of the trolls and Qt pros have not weighed in on this one.

    Does anyone want to comment?

  • I must be missing something somewhere.
    Or maybe the solution is too obvious for experts to comment on.
    After a week and more than 80 views no one cares to comment in this forum?
    Has no one ever wanted to get the text from a URL request?

    At least tell me if I am going in the wrong direction instead of continuing to allow me to stumble around in the dark.

  • I cant help you out here but,
    mayby you can try a qt chatroom if you want to have an answer with speed. There are also a lot of people willing to help you.
    When i read your last post, i have to say that the people here are very helpfull and willing to guide you in the right direction.
    So mayby no one knows the answer.
    Good luck on your search to find a solution though.

  • vinb I would be glad to chat with you but your profile does not list a chat ID nor any other way to contact you except this thread.

    If you are inclined to email me, my email address is in my profile. Thanks for being courteous enough to respond.

  • Im not unwilling to chat with you, but i dont know why we should. As i told you that i cannot help you out with your problem.
    I meant, maybi you can chat "here": and ask your questions.

Log in to reply