×

Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    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 a post on the forum which I think may be the solution (http://wiki.forum.nokia.com/index.ph...thods_from_QML).

    I have constructed a C++ header in this manner:
    Code:
    #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
    {
      Q_OBJECT
     
    public:
      URLSource(QObject *parent = 0) : QObject(parent) { }
     
      Q_INVOKABLE void getURL(const QString &intext)
      {
        QWebView *webWWV = new QWebView;
        webWWV->setUrl(QUrl(intext));
        QWebFrame *mainFrame = webWWV->page()->mainFrame();
        instr = mainFrame->toPlainText();
      }
     
      Q_INVOKABLE int getValue()
      {
        . . . ;
        return s; 
      }
    And additions to my QML project like this:

    Code:
    function updateUI() {
      URLSource.getURL(QString("http://www.mysite/afile.txt"));
      myobject.invalue = URLSource.getValue();
    }
     
    Component.onCompleted: {
        // collect text and parse values to plug into meters
        updateUI();
      }
    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&)]+0×25): undefined reference to `_imp___ZN8QWebViewC1EP7QWidget’
    debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0×50): undefined reference to `_imp___ZN8QWebView6setUrlERK4QUrl’
    debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0×84): undefined reference to `_imp___ZNK8QWebView4pageEv’
    debug/moc_wwvsource.o:moc_wwvsource.cpp:(.text$_ZN9WWVSource6getURLERK7QString[WWVSource::getURL(QString const&)]+0×8e): 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?

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Re: QtQuick and QWebFrame::toPlainText()

    NEW UPDATE

    Well as mentioned this method does 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 mentioned originally.

    In the C++ code, a QWebView is connected to a slot that is called when the URL is loaded. In the slot, a QWebFrame is created and the page text is put into a string. I have added enough debug code to know that the Qt C++ slot code is called at least once and the URL is downloaded to a public string.

    I have changed the main function to return the public string that was obtained by the slot. While the C++ code does have a value from the URL that is correct, that public string is not returned to QML in the return value.

    I have found no error or other indication for the string to not be returned to QML from my C++ object that is working otherwise.
    Last edited by ad5xj; 2011-04-21 at 17:51.

Similar Threads

  1. Qt SDK Version 1.1 Beta on Max OS X -- module "QtQuick" is not installed
    By ovjo12 in forum [Archived] Qt SDKs and Tools
    Replies: 8
    Last Post: 2011-04-11, 07:54
  2. QtQuick/QML or Native
    By bluechrism in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-02-27, 22:26
  3. to receive and send sms from and to mobile and PC in java
    By manoj_2580 in forum PC Suite API and PC Connectivity SDK
    Replies: 4
    Last Post: 2010-10-22, 16:21
  4. 6600 and SAP and HFP and Mercedes
    By wave129 in forum Bluetooth Technology
    Replies: 1
    Last Post: 2007-03-26, 11:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×