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. How to check internet connection in Qt
Forum Updated to NodeBB v4.3 + New Features

How to check internet connection in Qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    saravanavelu39
    wrote on last edited by
    #1

    Hi all,,
    @bool networkInterface::networkAvailable()
    {
    QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
    bool result = false;

    for (int i = 0; i < ifaces.count(); i++)
    {
        QNetworkInterface iface = ifaces.at(i);
        if ( iface.flags().testFlag(QNetworkInterface::IsUp)
             && !iface.flags().testFlag(QNetworkInterface::IsLoopBack) )
        {
    
            for (int j=0; j<iface.addressEntries().count(); j++)
            {
                if (result == false)
                    result = true;
            }
        }
    
    }
    return result;
    

    }
    @

    this code is checking internet and working correctly in windows,,,but if i disconnect the internet in ubuntu means still the online status is true,,Please give me a suggesstion,,
    Thanks,,

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jafarabadi.qt
      wrote on last edited by
      #2

      Hi saravanavelu39, How are you friend? :)
      I have a simple solution :)) very simple!!!
      just ping 8.8.8.8 ip and check output...
      Look at this:
      @QProcess pingProcess;
      QString exec = "ping";
      QStringList params;
      params << "-c" << "1" << IP;
      pingProcess.start(exec,params,QIODevice::ReadOnly);
      pingProcess.waitForFinished(-1);
      QString p_stdout = pingProcess.readAllStandardOutput();
      QString p_stderr = pingProcess.readAllStandardError();@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        saravanavelu39
        wrote on last edited by
        #3

        Hi Jafar,,
        Thanks for your reply,,,I used your code,,that is working correctly in ubuntu,,but the application some time hangs after using this code,,so could you please give me a some other suggesstion,,

        Thanks,

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jafarabadi.qt
          wrote on last edited by
          #4

          of course saravanavelu..
          There are some solution in this link
          i hope be useful :)
          http://ubuntuforums.org/showthread.php?t=1803980

          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