Your network check snippet seems a bit too complicated. You could simply just call the following method:
bool QNetworkConfigurationManager::isOnline () const
Returns true if the system is considered to be connected to another device via an active network interface; otherwise returns false.
If this does not work for someone, it very likely means that the internet connection is unreliably, especially if it does not work randomly.