Important: Please read the Qt Code of Conduct -

QNetworkReply abort problem

  • I don't know if I missed something from documentation but when I call abort during put request the reply never gets deleted (in example program hangs). To contrary when the query is successful (probably all buffer sent) the program terminates normal. Could it be problem with threads ? Could application->processEvents(); processes events not related to replay ? Is there any workaround to this because it breaks my test unit program ?

    @bool myClass::_stop = true;

    void myClass::destroyed(QObject * obj)
    _stop = false;

    void myClass::someAction()
    QApplication * application = ...;
    QNetworkAccessManager * netMng = ...;

    QByteArray * data = new QByteArray("Some data");
    QBuffer * buffer = new QBuffer(data);

    QNetworkRequest req(QUrl(""));

    QNetworkReply * rep = netMng->put(req, buffer);

    qDebug() << "send";

    //wait some time to call abort
    const int MAX_COUNTER = 10;
    int cnt = 0;
    while (rep->isRunning()) {
    if (cnt < MAX_COUNTER)
    else if (cnt == MAX_COUNTER)

    qDebug() << "stopped" << rep->error();

    connect(rep, SIGNAL(destroyed(QObject*)), SLOT(destroyed(QObject*)));

    while (_stop) application->processEvents();

    qDebug() << "Stopped";

Log in to reply