PDA

View Full Version : How to detect an internet connection ?



ouekah
29th March 2010, 20:15
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...

squidge
29th March 2010, 22:08
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.