Change file download from server

  • Hellow, i have problem:
    I have ini file, site, and when i download this file i cant read/write it through QSettings, but this file was create through QSettings, and after dowload file becomes harder to 5 bytes, i open it with Notepad ++



    I redact data:
    And file was normal after that(he weighed as originally), but also dont work
    I try to check status(), but it is there are no any errors
    Advance many thanks for your help!

    [EDIT: converted to image links, Volker]

  • Moderators

    Your links are broken, so we can't look into them.

  • Oh, sorry, i change it

  • Does anyone had this been?

  • Seems like your download code is broken. Can you show us the relevant bits (reading from the download stream, writing to the file).

  • Download
    @ QNetworkAccessManager manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply
    this, SLOT(replyFinished(QNetworkReply*)));
    Slot ReplyFinished/Save in file
    @QFile file("RizekQssEditorRefresh.ini");
    connect(qnr, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(changeUploadProgress(qint64, qint64)));
    if (! | QIODevice::Text))
    QTextStream out(&file);
    out << QVariant(qnr->read(1024)).toString().replace("\r\n","\n");
    Function openData / open ini file
    @ QSettings settings(QDir::currentPath() + "\RizekQssEditorRefresh.ini",QSettings::IniFormat);

  • Don't use a [[Doc:QTextStream]], but write the bytes directly to a [[Doc:QFile]].


    Side note:
    The connect in your slot replyFinished is useless, as the network action has been terminated at this point. The signal will never fire.

  • 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() ": 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 (! | 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!!

Log in to reply