ReDKiiL
22nd March 2015, 16:09
Hi guys.
I am in need of help.
I'm building an application that downloads a file from the web server but precisely a .zip file.
It downloads the file but when I open the file is corrupted.
#include "formpost.h"
#include "ui_formpost.h"
#include "qdebug.h"
FormPost::FormPost(QWidget *parent) :
QWidget(parent),
ui(new Ui::FormPost)
{
ui->setupUi(this);
carregarIpsum();
}
FormPost::~FormPost()
{
delete ui;
}
void FormPost::carregarIpsum(){
netw = new QNetworkAccessManager(this);
connect(netw,SIGNAL(finished(QNetworkReply*)),this ,SLOT(finishedSlot(QNetworkReply*)));
QUrl url("http://192.168.1.2/night/M5.zip");
netw->get(QNetworkRequest(url));
}
void FormPost::finishedSlot(QNetworkReply *reply){
if(reply->error() == QNetworkReply::NoError){
QFile other("Download.zip");
other.open(QIODevice::WriteOnly);
other.write(reply->readAll());
other.flush();
other.close();
}
reply->deleteLater();
}
I am in need of help.
I'm building an application that downloads a file from the web server but precisely a .zip file.
It downloads the file but when I open the file is corrupted.
#include "formpost.h"
#include "ui_formpost.h"
#include "qdebug.h"
FormPost::FormPost(QWidget *parent) :
QWidget(parent),
ui(new Ui::FormPost)
{
ui->setupUi(this);
carregarIpsum();
}
FormPost::~FormPost()
{
delete ui;
}
void FormPost::carregarIpsum(){
netw = new QNetworkAccessManager(this);
connect(netw,SIGNAL(finished(QNetworkReply*)),this ,SLOT(finishedSlot(QNetworkReply*)));
QUrl url("http://192.168.1.2/night/M5.zip");
netw->get(QNetworkRequest(url));
}
void FormPost::finishedSlot(QNetworkReply *reply){
if(reply->error() == QNetworkReply::NoError){
QFile other("Download.zip");
other.open(QIODevice::WriteOnly);
other.write(reply->readAll());
other.flush();
other.close();
}
reply->deleteLater();
}