Change file download from server
Thanks for your help!
But it is work only with text file, how can i download and save in file executable file?
It works just the same. The QByteArray of readAll() just contains the transmitted bytes. Nothing is manipulated. Just save it to a file like above and name it accordingly. On unixoid OSes like Linux and Mac OS X you must set the executable bit(s) in order to actually make it executable. "QFile::setPermissions() ":http://doc.qt.nokia.com/4.7/qfile.html#setPermissions is your friend for this.
You need to disable QIODevice::Text to correctly write into binary file btw
[quote author="Denis Kormalev" date="1309969287"]You need to disable QIODevice::Text to correctly write into binary file btw[/quote]
Isn't that disabled by default and one has to switch it on manually?
I try do it, but it is dont work, i write:
@ QNetworkAccessManager manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply)),this, SLOT(winFileReplyFinished(QNetworkReply*)));
QNetworkReply * networkReply = manager->get(QNetworkRequest(QUrl(label_6->text())));
connect( networkReply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(changeUploadProgress(qint64, qint64)));@
//In slot winFileReplyFinished
@ QFile file("Setup_Rizek_Qss_Editor.exe");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
And system create file Setup_Rizek_Qss_Editor.exe without ico with the size of 1.37 KB instead of 4 MB
And when you dont want to open it
Did you check what's in that file? You can open it with a text editor! Really!
The file size makes me guess you're dealing with an HTML redirection.
And for a binary file you must not use QIODevice::Text! Generally, you will not need it in most circumstances.
You are right, i have html code in this file, how can i circumvent it, and is it posible?
It depends on the contents of the file - the usual answer in dev world :-)
If it is just a plain redirect, you must react yourself (send a second request with the new URL). See the docs on "QNetworkRequest::Attribute":QNetworkRequest::Attribute, especially QNetworkRequest::RedirectionTargetAttribute for some further details.
If it is another download page one would have to investigate further.
Many thanks for your help!!