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);
    buffer->open(QIODevice::ReadOnly);

    QNetworkRequest req(QUrl("http://qt-project.org/"));

    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)
    cnt++;
    else if (cnt == MAX_COUNTER)
    rep->abort();
    application->processEvents();
    }

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

    connect(rep, SIGNAL(destroyed(QObject*)), SLOT(destroyed(QObject*)));
    rep->deleteLater();

    while (_stop) application->processEvents();

    qDebug() << "Stopped";
    }@


Log in to reply
 

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