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. Determine whether the network is connected

Determine whether the network is connected

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 162 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.
  • F Offline
    F Offline
    fanxinglanyu
    wrote on last edited by
    #1

    This is my code.But I have a problem. When the Internet is disconnected, it will show that the Internet is not disconnected for 1 minute.Thanks,I need your help.

        QHostInfo::lookupHost("www.baidu.com", this, &MainWindow::netWorkStatus);
    bool MainWindow::netWorkStatus(const QHostInfo& host)
    {
    
        if (host.error() != QHostInfo::NoError) {
            qDebug() << "Lookup failed:" << host.errorString();
            ui->label_2->setText("Broken network");
            return false;
        }else{
    
            qDebug()<<"";
            ui->label_2->setText("Connected to the Internet");
    
           // QHostInfo::abortHostLookup(lookupID);
    
            return true;
        }
    }
    
    J.HilkJ 1 Reply Last reply
    0
    • F fanxinglanyu

      This is my code.But I have a problem. When the Internet is disconnected, it will show that the Internet is not disconnected for 1 minute.Thanks,I need your help.

          QHostInfo::lookupHost("www.baidu.com", this, &MainWindow::netWorkStatus);
      bool MainWindow::netWorkStatus(const QHostInfo& host)
      {
      
          if (host.error() != QHostInfo::NoError) {
              qDebug() << "Lookup failed:" << host.errorString();
              ui->label_2->setText("Broken network");
              return false;
          }else{
      
              qDebug()<<"";
              ui->label_2->setText("Connected to the Internet");
      
             // QHostInfo::abortHostLookup(lookupID);
      
              return true;
          }
      }
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @fanxinglanyu please do not double post

      locked as duplicate of
      https://forum.qt.io/topic/123142/how-do-you-know-if-it-is-connected


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      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