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. No reply or error from QNetworkAccessManager GET request
Forum Updated to NodeBB v4.3 + New Features

No reply or error from QNetworkAccessManager GET request

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 4 Posters 6.7k 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.
  • cpperC Offline
    cpperC Offline
    cpper
    wrote on last edited by cpper
    #5

    Here is the code. The download starts when I click on a button in the gui.

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        nam(new QNetworkAccessManager)
    {
        ui->setupUi(this);
        connect(nam,&QNetworkAccessManager::finished,[](QNetworkReply* r){
            qDebug()<<QString(r->readAll());
            r->deleteLater();
        });
    }
    
    
    void MainWindow::on_pushButton_clicked()
    {  
        connect(nam->get(QNetworkRequest(QUrl("http://192.168.1.103"))),static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),[](QNetworkReply::NetworkError err){
            qDebug()<<err;
        });
    }
    
    aha_1980A 1 Reply Last reply
    0
    • cpperC cpper

      Here is the code. The download starts when I click on a button in the gui.

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow),
          nam(new QNetworkAccessManager)
      {
          ui->setupUi(this);
          connect(nam,&QNetworkAccessManager::finished,[](QNetworkReply* r){
              qDebug()<<QString(r->readAll());
              r->deleteLater();
          });
      }
      
      
      void MainWindow::on_pushButton_clicked()
      {  
          connect(nam->get(QNetworkRequest(QUrl("http://192.168.1.103"))),static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),[](QNetworkReply::NetworkError err){
              qDebug()<<err;
          });
      }
      
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @cpper: thanks.

      I don't see any obvious so far. Have you tried connecting the readyRead() signal and see if you can at least receive parts of the file?

      Good night!

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • cpperC Offline
        cpperC Offline
        cpper
        wrote on last edited by cpper
        #7

        I tried it now, and the signal is indeed fired 150+ times. Strange, I'll look more into it.
        Thanks for the help :)

        1 Reply Last reply
        0
        • cpperC Offline
          cpperC Offline
          cpper
          wrote on last edited by cpper
          #8

          Ok, so it works if the response has 32763 characters or less. That's quite close to 2^15(32768) so maybe it makes sense to anyone.

          aha_1980A 1 Reply Last reply
          1
          • cpperC cpper

            Ok, so it works if the response has 32763 characters or less. That's quite close to 2^15(32768) so maybe it makes sense to anyone.

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #9

            @cpper said in No reply or error from QNetworkAccessManager GET request:

            Ok, so it works if the response has 32763 characters or less. That's quite close to 2^15(32768) so maybe it makes sense to anyone.

            interesting. if nobody here knows an answer, I'd file this at bugreports.qt.io

            It may be related to your environment, but maybe the network developers have some hint for you.

            Qt has to stay free or it will die.

            aha_1980A 1 Reply Last reply
            1
            • aha_1980A aha_1980

              @cpper said in No reply or error from QNetworkAccessManager GET request:

              Ok, so it works if the response has 32763 characters or less. That's quite close to 2^15(32768) so maybe it makes sense to anyone.

              interesting. if nobody here knows an answer, I'd file this at bugreports.qt.io

              It may be related to your environment, but maybe the network developers have some hint for you.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #10

              So the report is: https://bugreports.qt.io/browse/QTBUG-65755

              Qt has to stay free or it will die.

              1 Reply Last reply
              1
              • cpperC Offline
                cpperC Offline
                cpper
                wrote on last edited by
                #11

                Indeed :)
                It's my first time I submit to bugreports.qt.io so I hope I did it right.

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  Check your reply buffer size. There are two options if you're running out of buffer space:

                  Set a bigger buffer with setReadBufferSize(). The documentation is kinda vague but it mentions that the available bytes can be larger than the buffer size (which I'm guessing makes the request sorta hang there until you make some more room in the buffer or it timeouts).

                  Instead of waiting for the whole thing to arrive connect to the readyRead() signal and read the data (i.e. empty the buffer) as it comes in chunks.

                  1 Reply Last reply
                  3
                  • cpperC Offline
                    cpperC Offline
                    cpper
                    wrote on last edited by
                    #13

                    Thanks Chris. It seems that setReadBufferSize() dosen't change anything. I tried to set it to the exact size of the incoming reply, or to a bigger value, but I get the same behavior.

                    It seems I can get the entire reply, in chunks, using readyRead signal. Printing readBufferSize() in the readyRead slot always prints 0, if I don't set in manually via setReadBufferSize().
                    I would still be happy to be able to read the entire reply via finished signal so I'll try some more things. I got a reply in my bugreport(link above), I tried setting up the headers, but still, the same result.

                    1 Reply Last reply
                    0
                    • cpperC Offline
                      cpperC Offline
                      cpper
                      wrote on last edited by cpper
                      #14

                      I made a mistake and wasted your and my time. When I saw that the

                      qDebug()<<QString(r->readAll());
                      

                      line in the finished slot doesn't print anything, I tried doing something like

                      qDebug()<<"test"<<QString(r->readAll());
                      

                      trying to see if the slot actually gets called at all. Since I got the same (lack of) any output(also no "test"), I assumed that the slot is never called. But I was wrong.

                      The problem has nothing to do with networking, it seems it's all about qDebug. I was trying to get rid of the \r\n characters(display them as newlines) and used QTextStream(stdout) instead of qDebug(). Not only I was able to display the mentioned characters as a newline in the output pane, but was also surprised to see the content from bigger files too. So it seems it's actually qDebug's << overload who couldn't handle a longer input.

                      Doing

                      qDebug()<<"test";
                      qDebug()<<QString(r->readAll());
                      

                      in the finished slot, or doing some proper debugging with a breakpoint would have saved me(and you) some time and effort.

                      So finally, the "issue":

                      QTextStream out(stdout); 
                      QString str1(32763,'X'); 
                      QString str2(32764,'Y');  
                      
                      qDebug()<<str1; //works
                      qDebug()<<str2; //no output
                      
                      out<<str2; //works
                      

                      I posted the same message in the bugreport.
                      Thanks aha_1980 and Chris for your support :)

                      jsulmJ 1 Reply Last reply
                      2
                      • cpperC cpper

                        I made a mistake and wasted your and my time. When I saw that the

                        qDebug()<<QString(r->readAll());
                        

                        line in the finished slot doesn't print anything, I tried doing something like

                        qDebug()<<"test"<<QString(r->readAll());
                        

                        trying to see if the slot actually gets called at all. Since I got the same (lack of) any output(also no "test"), I assumed that the slot is never called. But I was wrong.

                        The problem has nothing to do with networking, it seems it's all about qDebug. I was trying to get rid of the \r\n characters(display them as newlines) and used QTextStream(stdout) instead of qDebug(). Not only I was able to display the mentioned characters as a newline in the output pane, but was also surprised to see the content from bigger files too. So it seems it's actually qDebug's << overload who couldn't handle a longer input.

                        Doing

                        qDebug()<<"test";
                        qDebug()<<QString(r->readAll());
                        

                        in the finished slot, or doing some proper debugging with a breakpoint would have saved me(and you) some time and effort.

                        So finally, the "issue":

                        QTextStream out(stdout); 
                        QString str1(32763,'X'); 
                        QString str2(32764,'Y');  
                        
                        qDebug()<<str1; //works
                        qDebug()<<str2; //no output
                        
                        out<<str2; //works
                        

                        I posted the same message in the bugreport.
                        Thanks aha_1980 and Chris for your support :)

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #15

                        @cpper said in No reply or error from QNetworkAccessManager GET request:

                        qDebug()<<QString(r->readAll());

                        Please be aware that if you do this readAll() for qDebug the next call to readAll() will NOT return anything as the first one already returned the content!

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        cpperC 1 Reply Last reply
                        2
                        • jsulmJ jsulm

                          @cpper said in No reply or error from QNetworkAccessManager GET request:

                          qDebug()<<QString(r->readAll());

                          Please be aware that if you do this readAll() for qDebug the next call to readAll() will NOT return anything as the first one already returned the content!

                          cpperC Offline
                          cpperC Offline
                          cpper
                          wrote on last edited by
                          #16

                          @jsulm Yes, I'm aware of this.

                          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