QNetworkReply nerver finishes when connection is cut



  • Hey,

    I got this code and in my main function:

        QNetworkAccessManager* m = new QNetworkAccessManager();
    
        QTimer timer;
        timer.setSingleShot(true);
    
        timer.connect(&timer, &QTimer::timeout, [=](){
            qDebug() << "Send1";
            QNetworkReply *reply = m->put(QNetworkRequest(QUrl("http://qt-project.org")), QByteArray::fromStdString("DATA"));
            QEventLoop loop;
            QObject::connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
            if (!reply->isFinished()) {
                loop.exec();
            }
            qDebug() << "Got Finished1";
            reply->deleteLater();
        });
    
        QTimer timer2;
        timer2.setSingleShot(true);
    
        timer2.connect(&timer2, &QTimer::timeout, [=](){
            qDebug() << "Send2";
            QNetworkReply *reply = m->put(QNetworkRequest(QUrl("http://qt-project.org")), QByteArray::fromStdString("DATA"));
            QEventLoop loop;
            QObject::connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
            if (!reply->isFinished()) {
                loop.exec();
            }
            qDebug() << "Got Finished2";
            reply->deleteLater();
        });
    
        timer.start(5000);
        timer2.start(10000);
    

    Now I do the following test:

    1. With internet connection up -> Both requests finish!
    2. With internet connection down -> Both requests finish!
    3. Internet connection is up. I wait for the first request to finish, cut the connection. -> The second request never finishes.

    What is this? A bug in qt or am I doing something wrong?

    Thanks!
    Nathan


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.