Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] createRequest does not finish
Forum Updated to NodeBB v4.3 + New Features

[Solved] createRequest does not finish

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 866 Views 1 Watching
  • 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.
  • B Offline
    B Offline
    brcontainer
    wrote on last edited by
    #1

    I can not do QNetworkAccessManager::createRequest finalize request. I tried finished(QNetworkRequest), but nothing happens, see how was the WebInspector:

    !http://i.stack.imgur.com/7IA6s.png(error)!

    The request is pending and never ends.

    What am I doing wrong?

    My code:

    @QNetworkReply * myNAM::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData){
    QNetworkAccessManager *n = new QNetworkAccessManager();

     QNetworkRequest req(request.url());
    
     const QList<QByteArray>a = request.rawHeaderList();
     int j = a.length();
     int i=0;
    
     for(;i<j;++i){
      req.setRawHeader(a[i],request.rawHeader(a[i]));
     }
    
     QList<QNetworkCookie> cookies = CookiesGlobals->cookiesForUrl(request.url());
     n->cookieJar()->setCookiesFromUrl(cookies,request.url());
    
     QNetworkReply *p;
     if(op==PostOperation) {
      const QByteArray data = outgoingData->readAll();
      p = n->post(req, data);
     } eles {
      p = n->get(req);
     }
    
     QEventLoop loop;
     connect(p, SIGNAL(finished()), &loop, SLOT(quit()));
     loop.exec&#40;&#41;;
    
     QVariant statusCode = p->attribute(QNetworkRequest::HttpStatusCodeAttribute&#41;;
     if (statusCode.isValid()){
      int status = statusCode.toInt();
      qDebug() << "FB: " status;
     } else {
      qDebug() << "FB: statusCode isInvalid";
     }
     finished(p);
     return p;
    }@
    

    QT project: https://github.com/brcontainer/qt-helper

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brcontainer
      wrote on last edited by
      #2

      Solution, removed QEventLoop, update code:
      http://stackoverflow.com/a/17915208/1518921

      QT project: https://github.com/brcontainer/qt-helper

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved