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 keeps downloading wrong file...
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager keeps downloading wrong file...

Scheduled Pinned Locked Moved Solved General and Desktop
qnetworkaccessqnetworkaccessm
12 Posts 3 Posters 1.2k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 4 Nov 2021, 17:19 last edited by Dariusz 11 Apr 2021, 17:21
    #3
        connect(reply, &QNetworkReply::errorOccurred, this, &testApp::handleNetworkError, Qt::QueuedConnection);
        connect(reply, &QNetworkReply::finished, this, &testApp::handleNetworkFinished, Qt::QueuedConnection);
    
    ::handleNetworkError(QNetworkReply::NetworkError error) {
            qDebug() << "Network error : " << error;
            sender()->deleteLater();
        }
    
    ::handleNetworkFinished() {
            //qDebug() << "Handing version on thread?" << thread();
            auto reply = qobject_cast<QNetworkReply *>(sender());
            auto data = reply->readAll();
            if (data.size() > 0) {
                try {
                    qDebug() << data;
                   auto dec = data;
                    if (dec.size() > 0) {
    
                        auto hash = QCryptographicHash::hash(data, QCryptographicHash::Algorithm::Md5).toHex();
                        if (mLastFileVersionHash != hash) {
                            mLastFileVersionHash = hash;
                            qDebug() << "Updating file version, change happen!" << mLastFileVersionHash.toHex();
                        } else {
                            qDebug()  << dec.size() << hash.toHex();
                        }
                        //qDebug() << dec;
                    }
                }
                catch (...) {
    
                }
            } else {
                qDebug() << "No data?";
            }
            sender()->deleteLater();
        }
    

    I've now added this to code too, still no luck.

            request.setAttribute(QNetworkRequest::Attribute::CacheLoadControlAttribute, QNetworkRequest::CacheLoadControl::AlwaysNetwork);
    

    Hes magically making up the file out of thin air after file being deleted off ftp.

    J 1 Reply Last reply 4 Nov 2021, 17:23
    0
    • D Dariusz
      4 Nov 2021, 17:19
          connect(reply, &QNetworkReply::errorOccurred, this, &testApp::handleNetworkError, Qt::QueuedConnection);
          connect(reply, &QNetworkReply::finished, this, &testApp::handleNetworkFinished, Qt::QueuedConnection);
      
      ::handleNetworkError(QNetworkReply::NetworkError error) {
              qDebug() << "Network error : " << error;
              sender()->deleteLater();
          }
      
      ::handleNetworkFinished() {
              //qDebug() << "Handing version on thread?" << thread();
              auto reply = qobject_cast<QNetworkReply *>(sender());
              auto data = reply->readAll();
              if (data.size() > 0) {
                  try {
                      qDebug() << data;
                     auto dec = data;
                      if (dec.size() > 0) {
      
                          auto hash = QCryptographicHash::hash(data, QCryptographicHash::Algorithm::Md5).toHex();
                          if (mLastFileVersionHash != hash) {
                              mLastFileVersionHash = hash;
                              qDebug() << "Updating file version, change happen!" << mLastFileVersionHash.toHex();
                          } else {
                              qDebug()  << dec.size() << hash.toHex();
                          }
                          //qDebug() << dec;
                      }
                  }
                  catch (...) {
      
                  }
              } else {
                  qDebug() << "No data?";
              }
              sender()->deleteLater();
          }
      

      I've now added this to code too, still no luck.

              request.setAttribute(QNetworkRequest::Attribute::CacheLoadControlAttribute, QNetworkRequest::CacheLoadControl::AlwaysNetwork);
      

      Hes magically making up the file out of thin air after file being deleted off ftp.

      J Offline
      J Offline
      JonB
      wrote on 4 Nov 2021, 17:23 last edited by
      #4

      @Dariusz
      What happens when you put HTTPS://somePath.com/file/t.text into a web browser? Does that still access it?

      D 1 Reply Last reply 4 Nov 2021, 17:25
      0
      • J JonB
        4 Nov 2021, 17:23

        @Dariusz
        What happens when you put HTTPS://somePath.com/file/t.text into a web browser? Does that still access it?

        D Offline
        D Offline
        Dariusz
        wrote on 4 Nov 2021, 17:25 last edited by
        #5

        @JonB nope, the file is gone. There is a "lag" between my editing ftp file/renaming it to different file and browser acting on it, like 20-40 seconds or so. But QT bang on keeps loading the exact same from no idea when over and over again. I'm lost :- (

        J 1 Reply Last reply 4 Nov 2021, 17:30
        0
        • D Dariusz
          4 Nov 2021, 17:25

          @JonB nope, the file is gone. There is a "lag" between my editing ftp file/renaming it to different file and browser acting on it, like 20-40 seconds or so. But QT bang on keeps loading the exact same from no idea when over and over again. I'm lost :- (

          J Offline
          J Offline
          JonB
          wrote on 4 Nov 2021, 17:30 last edited by JonB 11 Apr 2021, 17:33
          #6

          @Dariusz
          It sounds external to Qt. You can even restart the app.

          Just in case the https is relevant. You have got your OpenSSL working with your Qt app, haven't you? And can you temporarily make your file available over http to see whether that would make any difference?

          And please make sure you're trying to access the same URL in your Qt program as you are testing and altering externally! Do some copy & paste :)

          D 1 Reply Last reply 4 Nov 2021, 17:34
          0
          • J JonB
            4 Nov 2021, 17:30

            @Dariusz
            It sounds external to Qt. You can even restart the app.

            Just in case the https is relevant. You have got your OpenSSL working with your Qt app, haven't you? And can you temporarily make your file available over http to see whether that would make any difference?

            And please make sure you're trying to access the same URL in your Qt program as you are testing and altering externally! Do some copy & paste :)

            D Offline
            D Offline
            Dariusz
            wrote on 4 Nov 2021, 17:34 last edited by Dariusz 11 Apr 2021, 17:35
            #7

            @JonB Mmmm What you mean I can start the app ?

            I did not touch OpenSSL, I do have one in project, but not sure if that one is relevant to Qt in any shape/form. I though that QNetwork library handles all that.
            As to url, I replaced HTTPS with HTTP, so far out of start it did not find file, so thats good, I uploaded file, 1-2 min later he found it. I've now pushed 3 more file versions-file overwrites.
            On filezilla it takes about 20-30 seconds to see change on ftp file (I'm using python to upload file).
            But then if I type adr in website - file is new, but Qt still downloads old file.
            I disabled all caches I could from examples above, but hes still stuck on the same file download :- ((((

            Last test is as follow
            HTTP instead of HTTP
            no file on server
            Error reply > Network error : QNetworkReply::ContentNotFoundError
            I copied file on Server
            Found file > did version OK
            I updated File
            No change
            I updated file again
            No Change
            I deleted file
            No Change

            Once he gets hte file. He just keeps it for evaaaaaaaaaaa..........

            J 1 Reply Last reply 4 Nov 2021, 17:43
            0
            • D Dariusz
              4 Nov 2021, 17:34

              @JonB Mmmm What you mean I can start the app ?

              I did not touch OpenSSL, I do have one in project, but not sure if that one is relevant to Qt in any shape/form. I though that QNetwork library handles all that.
              As to url, I replaced HTTPS with HTTP, so far out of start it did not find file, so thats good, I uploaded file, 1-2 min later he found it. I've now pushed 3 more file versions-file overwrites.
              On filezilla it takes about 20-30 seconds to see change on ftp file (I'm using python to upload file).
              But then if I type adr in website - file is new, but Qt still downloads old file.
              I disabled all caches I could from examples above, but hes still stuck on the same file download :- ((((

              Last test is as follow
              HTTP instead of HTTP
              no file on server
              Error reply > Network error : QNetworkReply::ContentNotFoundError
              I copied file on Server
              Found file > did version OK
              I updated File
              No change
              I updated file again
              No Change
              I deleted file
              No Change

              Once he gets hte file. He just keeps it for evaaaaaaaaaaa..........

              J Offline
              J Offline
              JonB
              wrote on 4 Nov 2021, 17:43 last edited by JonB 11 Apr 2021, 17:46
              #8

              @Dariusz said in QNetworkAccessManager keeps downloading wrong file...:

              Mmmm What you mean I can start the app ?

              You previously wrote:

              I EVEN restarted the app, he is still DOWNLOADING IT!! HOW O.O

              I was referring to that.

              I wonder whether it survives rebooting your machine?

              Anyway, try this:

               QUrl("HTTPS://somePath.com/file/t.text?1")
              

              It may or may not work. But if it does then, after you change the file externally, try

               QUrl("HTTPS://somePath.com/file/t.text?2")
              

              Does that help? The number could be generated from a current datetime function. This technique can be used to by-pass caching for pages which change content. Any difference? Not that I think you ought to have to do this, but would be interesting to know.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dariusz
                wrote on 4 Nov 2021, 18:12 last edited by
                #9

                testing left & right. Im slowly suspecting that my ftp server does not properly index/update/fetch files! Evil ftp providers!

                J 1 Reply Last reply 4 Nov 2021, 18:24
                0
                • D Dariusz
                  4 Nov 2021, 18:12

                  testing left & right. Im slowly suspecting that my ftp server does not properly index/update/fetch files! Evil ftp providers!

                  J Offline
                  J Offline
                  JonB
                  wrote on 4 Nov 2021, 18:24 last edited by JonB 11 Apr 2021, 18:24
                  #10

                  @Dariusz
                  But what is the difference between QUrl("HTTPS://somePath.com/file/t.text") versus same in a web browser?

                  Did you try the ? suffix?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dariusz
                    wrote on 4 Nov 2021, 21:37 last edited by
                    #11

                    Ok my FTP provider is piece of ..... Ive set up new ftp/server/etc on ec2. Everything works. SIGH!
                    Drama for nothing.
                    Thanks for helps bois! <3

                    J 1 Reply Last reply 5 Nov 2021, 07:09
                    1
                    • D Dariusz
                      4 Nov 2021, 21:37

                      Ok my FTP provider is piece of ..... Ive set up new ftp/server/etc on ec2. Everything works. SIGH!
                      Drama for nothing.
                      Thanks for helps bois! <3

                      J Offline
                      J Offline
                      JonB
                      wrote on 5 Nov 2021, 07:09 last edited by
                      #12

                      @Dariusz
                      I still don't get how come you said the same URL worked to access the correct content from a web browser but not from QNetworkRequest, which was the important thing....

                      1 Reply Last reply
                      0

                      12/12

                      5 Nov 2021, 07:09

                      • Login

                      • Login or register to search.
                      12 out of 12
                      • First post
                        12/12
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved