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. QNetworkAccessManager send data incomplete on windows

QNetworkAccessManager send data incomplete on windows

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 650 Views
  • 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.
  • A Offline
    A Offline
    aidinMC
    wrote on last edited by
    #1

    I have a trouble with QNetworkAccessManager in windows. I wrote the following code to submit request ,it works on ubuntu perfectly but on windows send just 16384 bytes!! It seems request execute just once and freeze.

    QString concatenated = username + ":" + pass;
    QByteArray hash = concatenated.toLocal8Bit().toBase64();
    QString headerData = "Basic " + hash;
    QNetworkRequest request = QNetworkRequest(QUrl(baseURL));
    
    request.setRawHeader("Authorization", headerData.toLocal8Bit());
    request.setRawHeader("Content-Type", "application/json");
    
    QNetworkReply * reply = nam->post(request,data);
    connect(reply,&QNetworkReply::uploadProgress,this,&myClass::uploadProgress);
    

    in uploadProgress method:

    qDebug() << sent << " " << total;
    if(total && sent){
        int result = (sent*100)/total;
        emit uploaded(result);
    }
    

    output:

    16384 632054 // AND EVERY THINGS STOP UNTIL I GET QNetworkReply::RemoteHostClosedError ERROR CODE
    
    JonBJ 1 Reply Last reply
    0
    • A aidinMC

      I have a trouble with QNetworkAccessManager in windows. I wrote the following code to submit request ,it works on ubuntu perfectly but on windows send just 16384 bytes!! It seems request execute just once and freeze.

      QString concatenated = username + ":" + pass;
      QByteArray hash = concatenated.toLocal8Bit().toBase64();
      QString headerData = "Basic " + hash;
      QNetworkRequest request = QNetworkRequest(QUrl(baseURL));
      
      request.setRawHeader("Authorization", headerData.toLocal8Bit());
      request.setRawHeader("Content-Type", "application/json");
      
      QNetworkReply * reply = nam->post(request,data);
      connect(reply,&QNetworkReply::uploadProgress,this,&myClass::uploadProgress);
      

      in uploadProgress method:

      qDebug() << sent << " " << total;
      if(total && sent){
          int result = (sent*100)/total;
          emit uploaded(result);
      }
      

      output:

      16384 632054 // AND EVERY THINGS STOP UNTIL I GET QNetworkReply::RemoteHostClosedError ERROR CODE
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @aidinMC
      Is your host really consuming the bytes sent under/from Windows? Looks like a buffer has been filled but not read out?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aidinMC
        wrote on last edited by
        #3

        How can I check it?
        May it Qt bug on windows 10?
        Because this code works perfectly on Ubuntu and I sent over 500MB data to server!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aidinMC
          wrote on last edited by
          #4

          I tested this code too, The result no change:

          QString concatenated = username + ":" + pass;//username:password
          QByteArray hash = concatenated.toLocal8Bit().toBase64();
          QString headerData = "Basic " + hash;
          QHttpMultiPart *httpMultiPart = new QHttpMultiPart(nam);
          QHttpPart *httpPart = new QHttpPart();
          httpPart->setRawHeader("Authorization", headerData.toLocal8Bit());
          httpPart->setRawHeader("Content-Type", "application/json");
          httpPart->setBody(data);
          
          httpMultiPart->append(*httpPart);
          
          QNetworkReply* reply = nam->post(QNetworkRequest(QUrl(baseurl)),httpMultiPart);
          
          JonBJ 1 Reply Last reply
          0
          • A aidinMC

            I tested this code too, The result no change:

            QString concatenated = username + ":" + pass;//username:password
            QByteArray hash = concatenated.toLocal8Bit().toBase64();
            QString headerData = "Basic " + hash;
            QHttpMultiPart *httpMultiPart = new QHttpMultiPart(nam);
            QHttpPart *httpPart = new QHttpPart();
            httpPart->setRawHeader("Authorization", headerData.toLocal8Bit());
            httpPart->setRawHeader("Content-Type", "application/json");
            httpPart->setBody(data);
            
            httpMultiPart->append(*httpPart);
            
            QNetworkReply* reply = nam->post(QNetworkRequest(QUrl(baseurl)),httpMultiPart);
            
            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @aidinMC
            I don't know what your issue is. But is this your only code? You don't want to put in any code for, say, errorOccurred or finished or anything else?

            1 Reply Last reply
            1
            • A Offline
              A Offline
              aidinMC
              wrote on last edited by
              #6

              After two days finally, I found why it happened! It because I emit the signal in uploadProgress directly! I changed the uploadProgress code like below and it works perfectly now!

              qDebug() << sent << " " << total;
              if(total && sent){
                  int result = (sent*100)/total;
                  QTimer::singleShot(5,[this,result](){
                     emit uploaded(result);   
                  }
              }
              
              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