[Qt-interest] What's the best way to determine online status?

Murphy, Sean M. sean.murphy at gd-ais.com
Thu Oct 15 23:48:25 CEST 2009


>> The only way I've thought of at the moment is right when I launch, 
>> request a page from Google Maps, and set up a QNetworkReply watching 
>> for a error signal.  If I get an error, then I'll assume I'm on the 
>> LAN and use the old Qt3 widget for the remainder of that session, if 
>> I get the reply back successfully from Google Maps, then I'll know 
>> I'm online and I'll use my WebKit version.
> I think this is the only practical (and portable!) solution. Just try 
> what you want to do and see if it fails. All the checking-interfaces-
> and-try-to-guess- the-right-thing is really just guessing. If the 
> interface is up and has an ip- address, that is no sign that you are 
> connected to the net. And if the device(s) you check are all down, it 
> doesn't really mean that there is no connection. Could be there are 
> some obscure interfaces which you didn't check. And implementing the 
> different check-for-interfaces for the different os'es is probably a 
> pain in the...

Right, checking the network interface status won't help.  The way our
application is used, the user will almost always be on *a* network, but
50% of the time that network isn't connected to the Internet, 50% of the
time it is.  So I think checking to see whether I can get to an Internet
site (like Google Maps) is the way to go.
 
> Why do you use two widgets? Why not use the webview for all display 
> and just show the google-maps background only when a connection is
made?

I need to show a collection of geographically located items to the user,
allowing them to visually see the relationship between them.  I also
need to draw geographically located polygons, circles, lines, etc.
Those items need to be scaled correctly.  The sizes of these items also
needs to be to scale.  The old Qt3 widget I have does this perfectly,
but over a blank grey background.  It's QCanvas based, allowing for easy
creation and placement of all the various items I need to put on it.
The code for it has been tested for 10 years and works fine, with the
exception of the lack of background imagery.

Replacing the QCanvas widget with the QWebView/Google Maps idea seems
like it makes sense if I'm online.  But in that case, I'd be using the
Google Maps API to draw the waypoints, polygons, circles, lines, etc.
So I'd just be writing HTML that calls Google Maps' functions to
correctly place them over the background imagery.  In the case where I'm
not online, but still using a QWebView class, I'd need to use a QPainter
to correctly draw all the items in their relative positions and sizes, I
wouldn't be using any webkit features at all.  Basically I'd need to
port my 10 year old Qt3 widget from QCanvas to QWebView.

It seems quicker to just use my existing widget using the Qt3
compatibility libraries as is whenever I'm not online, and use a
QWebView with Google Maps' API when I am online, than try to port my
widget over to a QWebView when I'm not using any webkit features at that
point.

I hope I'm making sense!
Sean

 




More information about the Qt-interest-old mailing list