Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Need Code to check Internet connection in system at the time of Application Start for Release Mode

    General and Desktop
    3
    3
    3254
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      Zain last edited by

      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

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        @
        QNetworkConfigurationManager *netConMan;
        @

        Either you are not showing the whole code, or this variable is not initialised (no call to "new").

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • V
          vidar last edited by

          (If you encounter differences (crash in Release and no crash in Debug etc.) between Debug and Release Compilations, it is mostly because of not initialized pointers/objects or array overflows)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post