Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need Code to check Internet connection in system at the time of Application Start for Release Mode

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.4k Views
  • 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 Offline
    Z Offline
    Zain
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @
      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
      0
      • V Offline
        V Offline
        vidar
        wrote on last edited by
        #3

        (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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved