Is there a simple way to detect whether a computer is connected to the internet using QT ?
My application behaves differently whether it is in offline mode or online mode...
Is there a simple way to detect whether a computer is connected to the internet using QT ?
My application behaves differently whether it is in offline mode or online mode...
The simplest way would be to attempt to connect a computer that is outside your LAN, such as Google. If the call succeeds, you have internet access. This may not work on some PCs at various companies, as they might only have internet access via a proxy, so they can download webpages, send/receive email, but has no internet connection otherwise.
If your writing code for windows, then there APIs such as InternetGetConnectedState(), but even things like this are not 100% reliable. You need to actually try to connect somewhere yourself to prove 100%
The typical way is to try to connect directly first, and if that fails, figure out the local proxy settings (if any) and try again via that route.
Last edited by squidge; 29th March 2010 at 22:15.
Bookmarks