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. Using QNetworkAccessManager to download a big file.

Using QNetworkAccessManager to download a big file.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 173 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote last edited by
    #1

    I need to download and write a big file. In order to to this I'm Using QNetworkAccessManager. The problem is that I need to write the file directly but the write procedure is very slow because the special drive is not fast as an hard disk.

                    QNetworkAccessManager NetworkAccessManager;
                    QNetworkReply *pQNetworkReply= NetworkAccessManager.get(QNetworkRequest(QUrl::fromEncoded(Path.toLocal8Bit())));
                    QByteArray QBABuffer;
                    if (pQNetworkReply) {
                        connect(pQNetworkReply, &QNetworkReply::readyRead, [&]() {
                        ...
    

    The problem is that the readyread implementation must be fast. If I write in it a slow function the software firtly increase the ram usage and then goes to crash.
    Is there a way to pause the object QNetworkReply or to reduce the speed of the dowloader?

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote last edited by hskoglund
      #2

      Hi, you could try doing partial downloads by specifying "Range" and "bytes" in the headers (this requires that the server supports partial downloads but most do nowadays.) More here

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote last edited by
        #3

        Hi,

        If I remember correctly one thing you could do is to set a small read buffer size so it should slow the transmission.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • piervalliP Offline
          piervalliP Offline
          piervalli
          wrote last edited by
          #4

          In the opposite aproce i have down 3 phase

          1. initialize to file for upload and chunk size
            2 .parallel upload
          2. finalize

          You should do

          1. initialize to file for download and chunk size
            2 .parallel download
          2. finalize
          1 Reply Last reply
          0
          • mrdebugM Offline
            mrdebugM Offline
            mrdebug
            wrote last edited by
            #5

            After a long brainstorming till the brain explosion I have decided to use the QTcpSocket object implementing the http request by hand like this

                                QTcpSocket TcpSocket;
                                TcpSocket.connectToHost(Url.host(), Url.port());
                                if (TcpSocket.waitForConnected()) {
                                    TcpSocket.write(QString("GET "+ Url.path()+ " HTTP/1.1\r\n").toLatin1());
                                    TcpSocket.write(QString("Host "+ Url.host()+ " \r\n").toLatin1());
                                    TcpSocket.write(QString("Connection: close\r\n\r\n").toLatin1());
                                    if (TcpSocket.waitForBytesWritten()) {
                                        while (TcpSocket.waitForReadyRead()) {
                                        ...
            

            Seems to work

            Need programmers to hire?
            www.labcsp.com
            www.denisgottardello.it
            GMT+1
            Skype: mrdebug

            1 Reply Last reply
            0
            • piervalliP Offline
              piervalliP Offline
              piervalli
              wrote last edited by
              #6

              If URL contains a space 0x20, Is It work?

              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