Need Code to check Internet connection in system at the time of Application Start for Release Mode
-
Hello All,
In my Qt application i need to check internet connection on application start.
I have used following two code logics.
First:
@ QNetworkConfigurationManager *netConMan;
if(!netConMan->isOnline()) { msg.setText("You must be online to run this application.Please make sure you are connected to the internet then relaunch the application!"); msg.exec(); QCoreApplication::exit(0); }@
Second :
@ QNetworkAccessManager* manager = new QNetworkAccessManager(this);
QNetworkReply *reply234;
QEventLoop loop1;reply234 =manager->get(QNetworkRequest(QUrl("http://www.google.com"))); connect(reply234, SIGNAL(finished()), &loop1, SLOT(quit())); loop1.exec(); if (reply234->error() != QNetworkReply::NoError) { msg.setText("You must be online to run this application.Please make sure you are connected to the internet then relaunch the application!"); msg.exec(); QCoreApplication::exit(0); }@
I am connected with Internet.
Both above logic is working fine when I am building my application in "Debug Mode" .But when I make build in "Release Mode" it alert message
@You must be online to run this application.Please make sure you are connected to the internet then relaunch the application!@
I am not getting what is the difference in Debug and Release mode for this logic.
Please suggest logic or code me to check Internet Connection when build in Release mode.Thanks in Advance.
Zain
-
@
QNetworkConfigurationManager *netConMan;
@Either you are not showing the whole code, or this variable is not initialised (no call to "new").