views:

193

answers:

1

I wish to use QtWebKit to load a url for display, but, that's the easy part, I can do that. What I wish to do is record / log xml as I go. My attention here is to record and database certain details on the fly, by recording those details.

My problem is, how to do this all on the fly, without requesting the same url from the server twice, once for the xml, and the second time to view the url.

My hope here, is to implement a very fast way of recording set data as the user passes over it. Take for example, rather then have to type out details displayed by a website, I wish to have those details chucked into a database as I the user views the website.

Now, I am using QtWebKit, and I have everything pretty much solved viewing wise. I have a loadUrl() routine which calls load(url) inside the qwebview.h

The problem is, how do I piggyback xml parsing on top of this?

A: 

In your loadUrl do the download of the url yourself using the HTTP download facilities Qt already provides (QNetworkRequest and friends).

Once you got the data, parse and log it and use:

void QWebView::setHtml ( const QString & html, const QUrl & baseUrl = QUrl() )

To set it into the QWebView manually. The second url parameter is the url you have, which will be used as a base url for the elements that are referenced from the page.

If you are not sure you downloaded html, then use:

void QWebView::setContent ( const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl() )

You can also do the inverse. Just call QWebView::load(url) in your method, and once the transfer is complete, use QWebView::mainFrame() to get the main frame and then QWebFrame::toHtml() to get the content, which you can parse and log as you wish.

duncan
Okay, the above sounds pretty spot on, the only thing of significance might be the use of frames in this page. My first attempt to do all of this was in Visual studio, but I found only the first frame that loads was able to be used, and that I lost control of it afterwards. But I have a feeling that I'll have a better time of it this time. I'll attempt to first write the file to disk, and then load it using setHTML.Also, there will also be javascript involved, but it's not required for parsing. Well, cross fingers, here I go :P
Beren Scott
Okay, so, as an example, I took a look at the arora code located in the sourceviewer, which is essentially close to what I'd be doing, and it's written like this:[code] m_request = new QNetworkRequest(url); m_request->setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); m_reply = BrowserApplication::networkAccessManager()->get(*m_request); connect(m_reply, SIGNAL(finished()), this, SLOT(loadingFinished())); m_reply->setParent(this);[/code]the m_request I understand including the prefer cache bit, I could even use the inverse
Beren Scott