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 doesn't download whole web page
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager doesn't download whole web page

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 7.6k 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.
  • K Offline
    K Offline
    Kxyu
    wrote on last edited by
    #1

    Hi. I'm trying to donwload page via http using QNetworkAccessManager
    I store data in QByteArray and append readAll() from respective QNetworkReply object on each call of readyRead signal

    but when I check QByteArray content on finished signal of QNetworkAccessManager, it contains not whole page, it is cut in a certain place.
    I see there is a kind of limitation, but I can't find the way to avoid it

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Did you really read the last chunk?

      finished() is emitted as soon as the request is done from a protocol perspective. You may have pending data in the reply that you have not read yet. It's good practice to call readAll() in your slot connected to finished() a last time to get the last chunk of data.

      If your data is not big or you do not need the data chunkwise as soon as possible, you can have QNetworkReply collect the data and read the whole page after finished() with readAll(). See "QNetworkReply::finished() ":http://doc.qt.nokia.com/stable/qnetworkreply.html#finished for some details.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kxyu
        wrote on last edited by
        #3

        I tried doing only readAll() on QNetworkAccessManager finished signal, and it downloads the same exact piece of page!
        is there any significant difference between QNetworkAccessManager finished and QNetworkReply finished?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          The finished signal of QNetworkReply is connected to a private slot of QNetworkAccessManager which in turn immediately emits finished(QNetworkReply*). So, no, there is no significant difference.

          As things work for most of the other people, it would be handy, if you could provide us a small, complete, compilable and running example that demonstrates the error and that we can run on our boxes.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kxyu
            wrote on last edited by
            #5

            Well thr code is as following
            @
            void bot::recieveId() // this function initiates request
            {
            connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(idRecieved(QNetworkReply*)));
            manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));//it's not actual URL, but problem is the same
            }

            void bot::idRecieved(QNetworkReply _reply) // this slot dumps the whole data
            {
            rawData=_reply->readAll();
            qDebug()<<rawData;
            disconnect(manager,SIGNAL(finished(QNetworkReply
            )),this,SLOT(idRecieved(QNetworkReply*)));
            }
            @
            manager and rawData are QNetworkAccessManager (instantiated in counstructor) and QByteArray (static)
            the last thing I have in console is
            @
            <li><a href="http://qt.nokia.com/developer/eclipse-integration">Eclipse plug-in</a></li>
            @

            while there is a hundred or more strings after

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              I just tried and it works for me. I get the complete page.

              I'm on Mac OS X 10.6, Qt 4.7.0.

              Do you have any proxy settings in your program? Or some corporate hidden proxy inbetween? Can you get the page correctly with another tool on the command line, eg.

              @
              curl http://qt.nokia.com
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kxyu
                wrote on last edited by
                #7

                well, I think I found the answer. I tried some operations with rawData (like finding </html> tag) and everything was ok. I guess it's just a limitation of qDebug()

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mady
                  wrote on last edited by
                  #8

                  Hi volker,

                  I am using QNAM to download a XML file from server but getting "connection timed out" error message in reply. In your previous post you were asking whether Kxyu is using proxy in his program. My program is behind a corporate proxy, can it cause this issue? If yes, could you please let me know how to resolve the problem?

                  Note: Through browser I can access the page successuflly

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dangelog
                    wrote on last edited by
                    #9

                    What's the point of necroposting? Please, start a brand new thread with all the relevant information.

                    Software Engineer
                    KDAB (UK) Ltd., a KDAB Group company

                    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