Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QNetworkReply abort problem

    General and Desktop
    1
    1
    1346
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 8
      8majkel8 last edited by

      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";
      }@

      1 Reply Last reply Reply Quote 0
      • First post
        Last post