QNetworkAccessManager keeps downloading wrong file...
-
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.
-
@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 :- (
-
@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 overhttp
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 :)
-
@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 ChangeOnce he gets hte file. He just keeps it for evaaaaaaaaaaa..........
-
@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.