[Interest] QWebview signals with dynamic web pages

Kevin McGuire kmcg3413 at gmail.com
Mon Mar 5 19:51:55 CET 2012

I have worked with many things like this before. I want to offer some
of my solution only as hopefully to help you. Your
problem is really simple so do not give up, in case you still end up
with problems. I think your solution to just keep reparsing
the code every 10-ms is quite adequate! And, very good job.

I would have done it just like you did in a rush just to get it
working. Then, if possible, if you want to make it truely efficent
then what you may want to do is possibly create your own network
socket and connect and try using HTTP/1.0 headers,
and then just manually parse the document. This would not take as much
code as you think, and if done correctly would
be just as functionaly stable as using the QWebView if not more realiable.

Lot of time just create a synchronous socket and send the simple
string "GET <url> HTTP/1.0\?\?". I forget, if it is character
0x0a or 0x0d you have to send once or twice. But, if you get it right
it will send you the headers with content-length and all
the data. Just close the socket, and parse the data (not complete DOM
parser). Just simple one function parser to pull elements

But, my opinion can be very contrary to popular choice. However, this
is just something to keep in mind! But, your QWebView is
great idea too! And, it works!

On Mon, Mar 5, 2012 at 8:39 AM, Murphy, Sean M. <sean.murphy at gd-ais.com> wrote:
>> > I'm trying to read an 8-channel temperature sensor device that outputs its
>> > data via a web interface.  Viewing the device's web page via a normal web
>> > browser, or via QWebView::load(), I can see the temperatures correctly.  The
>> > temperature values are "live" in that they automatically update about once a
>> > second, without the user having to manually reload/refresh the browser.  My
>> > HTML skills are pretty minimal, so I'm not sure what magic it uses to update
>> > those parameters, but I don't see any sort of <meta http- equiv="refresh"
>> > content="1"> tag.
>> That might be some AJAX-y magic I guess? :) There might be some JS
>> code that is sending some request and updating only a particular DOM
>> element?
> That certainly seems to be the behavior, and that's where it gets beyond my level of web knowledge, might be time to start learning that - it seems this whole web fad might be here to stay!
>> Is it possible for you to alter the web pages code? If so, you could
>> probably use the webkit-bridge concept where the page (via some
>> modified JS code) calls a Qt slot on each refresh.
> I can't alter the web page's code, it's coming from a vendor's device that has an embedded webserver installed.  So closed architecture, closed source, etc...
>> Or if thats not possible, how about inspecting the DOM and finding out
>> the value of the required element? I guess you're already doing that
>> on page load, but you probably don't have to refresh the page from
>> outside as the page is doing that itself. If you can find the refresh
>> time that the page is using, you could use the same refresh freq for
>> parsing the DOM tree once a page load completes. Would that work?
> That's sort of what I'm doing now.  My initial code had a slot that would parse the HTML for the values I'm looking for.  I connected that slot to the QWebView's loadFinished() signal, which worked ONCE; on the initial connection to the web server only.  So what I've now done is created a QTimer running every 100ms that keeps calling loadFinished(), which keeps reparsing the HTML, and this works.
> So the raw HTML is changing - I'm just surprised that Qt doesn't seem to have any signals that get triggered off from this...
> Sean
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

More information about the Interest mailing list