I have this code, written in qt 5.15:
Widget::Widget()
{
manager = new QNetworkAccessManager(this);
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl("http://example.com")));
connect(reply, &QNetworkReply::readyRead, this, &Widget::replyFinished));
}
void Widget::replyFinished(QNetworkReply* reply)
{
// some processing here
qDebug() << reply.readAll();
}
It works as expected, but I wonder, is there a risk to miss the signal emmited by QNetworkReply?
I tested that if I had some delay (with QThread::sleep(1);) between the get and the connect, replyFinished is not called.
Is there a method to ask an object to resend a signal if it has been missed?
QNetworkReply sends the signal from another thread, so there is indeed a possible race condition here.
To guard against it, you can do this:
Note that your replyFinished can get called twice.
Also,
readyReaddoes not mean entire reply has arrived, so it does not mean "reply finished".