0

I'm using two ip cameras from Axis Communications for my application. I want to check if the cameras are ever disconnected. Is it possible to do so by the use of QNetworkAccessManager and QNetworkReply?

The prototype of what I tried is like the following way:

QNetworkAccessManager *m_networkAccessManager = new QNetworkAccessManager();
QNetworkReply *m_networkReply = m_networkAccessManager->get(QNetworkRequest(camUrl));
if (!m_networkReply)
{
   delete m_networkAccessManager;
   qDebug()<<"Camera not found"<<endl;
}

connect(m_networkReplyCam, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(cameraDisconnected(QNetworkReply::NetworkError)));

void MainWindow::cameraDisconnected(QNetworkReply::NetworkError)
{
    qDebug()<<"Camera Disconected"<<endl;
}

But the slot cameraDisconnected never seem to gets invoked. I also tried connect with finished() signal from QNetworkReply like the following:

connect(m_networkReplyCam, SIGNAL(finished()), this, SLOT(cameraDisconnected()));

But even then the slot never gets called.

What am I doing wrong?

Thanks.

the_naive
  • 2,936
  • 6
  • 39
  • 68

1 Answers1

0

Your request will timeout after some time if the host is unreachable. There is no built-in way to set specific timeout in QNetworkRequestor QNetworkAccessManager so one possibility is to implement your own timer to abort after a particular time. There are multiple examples to do that like 1, 2 and 3.

Community
  • 1
  • 1
talamaki
  • 5,324
  • 1
  • 27
  • 40