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. How to resume an old download in an file QtNetwork
QtWS25 Last Chance

How to resume an old download in an file QtNetwork

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.2k 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.
  • D Offline
    D Offline
    developer
    wrote on last edited by
    #1

    how to resume an old download in an file QtNetwork i know how to pause an resume but i have started a download and then paused it and then quit my application and then i have to open my application again and then resume so here is the problem how do i write the new data at the end of file i have opened the file in append mode and then write but the problem in append mode it will add data at the last
    so whenever the downloadprogress ic alled i read the whole downloaded to file but in append mode it will add and so file is corrupt i have seen everythin every example and even arora arora has a very ordinary download manager which does not have this feature

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      You need to signal to the server that you don't want to get the file starting from the beginning but at some byte offset. This can be done via the HTTP request header, see the RFC specifications about this. The appropriate header information can then be written to a QNetworkRequest with setRawHeader.

      //EDIT: Here are the necessary specifications: https://tools.ietf.org/html/rfc2616 section 14.35

      1 Reply Last reply
      0
      • D Offline
        D Offline
        developer
        wrote on last edited by
        #3

        i know this man and i have already done it and i am getting the file after the pos but the problem is with saving with QFile please give me a small example

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          I don't understand this:

          bq. i have opened the file in append mode and then write but the problem in append mode it will add data at the last
          so whenever the downloadprogress ic alled i read the whole downloaded to file but in append mode it will add and so file is corrupt

          What are you saying is your problem?
          Opening in append mode and continue writing is the correct way.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            developer
            wrote on last edited by
            #5

            see my problem
            i have opened the file in append mode now every time download progress is called i write the data to file everything seems ok but not now see
            i am reading the whole reply (this is he only way i have) into file so
            olddata = olddata + all the datat downloaded till now
            file = olddata
            now you see the file is appending the whole downloaded till that time agagin so it will append the download every times this function is called ih ope this understands

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on last edited by
              #6

              show the code of the slot connected to QNetworkReply::downloadProgress. I still don't see why a normal QFile::write would add all the old data and the new chunk to the file. Considering that a QIODevice::read (on the QNetworkReply) advances its internal position.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                developer
                wrote on last edited by
                #7

                @void downloadfile::savedownloaded(qint64 downloaded, qint64 total)
                {
                file->write(reply->readAll());
                int percentage = 0;
                if(total > 0)
                {
                qDebug() << "yooo";
                percentage = ((downloaded+downloadsizeatpause) * 100) / (downloadsizeatpause+total);
                }
                qDebug() << "foo" << downloadsizeatpause;
                emit downloadprogress(downloaded+downloadsizeatpause , total+downloadsizeatpause , percentage);
                }@

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DerManu
                  wrote on last edited by
                  #8

                  Have you tried connecting that slot to readyRead? What does bytesAvailable() return in each iteration before and after readAll?

                  This doc paragraph might also be interesting for you:
                  The downloadProgress() signal is also emitted when data is received, but the number of bytes contained in it may not represent the actual bytes received, if any transformation is done to the contents (for example, decompressing and removing the protocol overhead).

                  It's not clear what this is supposed to mean:

                  bq. now you see the file is appending the whole downloaded till that time agagin so it will append the download every times this function is called ih ope this understands

                  This sounds as if QNetworkReply isn't a sequential device and you somehow reset the position to 0 at every read. But it's sequential so that shouldn't happen. Are you sure you open your file properly and the error isn't in some other part of the code that handles the file?

                  (Further you might want to look up an indian C++/Qt forum, it's really hard figuring out what you're actually trying to say.)

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

                    how you know i am an indian i am trying opening the file in readwrite mode and seeking the file to last i hope this works posting the code soon sfetr developing

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bapzangbo
                      wrote on last edited by
                      #10

                      developer I'm also write download program but Im amater in QT programming, Can you show your code for me reference
                      thanks

                      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