PDA

View Full Version : networkAccessibleChanged signal never gets called



INeedADollar
30th September 2019, 22:07
Hello! I am trying to detect when I lose connection to Internet, for example when I cannot load any site or any application that connects to Internet.
I am trying this with QNetworkAccesManager but signal networkAccessibleChanged never gets called.

My code:


mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
{
this->setGeometry(400, 400, 400, 400);
manager = new QNetworkConfigurationManager();
pManager->setConfiguration(manager->defaultConfiguration());
connect(pManager, &QNetworkAccessManager::networkAccessibleChanged, this, &mainWindow::test);
}

void mainWindow::test(QNetworkAccessManager::NetworkAcc essibility access){
qDebug() << access;
}


How can I solve this? Thank you!

d_stranz
30th September 2019, 22:59
How can I solve this? Thank you!

It is possible that your patience ran out before the OS finally notified your app that the network connection timed out. Depending on the platform, the time interval between the physical loss of a connection and the timeout can be minutes.

INeedADollar
1st October 2019, 18:12
I don't think that is the problem because I waited 30 minutes without Internet Connection and nothing happened. Do you know other method to react when computer loses Internet Connection?

d_stranz
1st October 2019, 18:38
Do you know other method to react when computer loses Internet Connection?

It is probably OS-specific. Here's an article on network connection heartbeats (https://www.rabbitmq.com/heartbeats.html) which might give you some ideas. Edit - it looks like this might be specific to the RabbitMQ product, whatever that is. But it has to be relying on some underlying protocol implemented at the network stack level.

INeedADollar
5th October 2019, 22:32
Thank you very much for help!