Solved Determine whether the network is connected
-
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; } }
-
@fanxinglanyu please do not double post
locked as duplicate of
https://forum.qt.io/topic/123142/how-do-you-know-if-it-is-connected