#ifndef GETFILE_H
#define GETFILE_H
#include <QObject>
#include <QtGui>
#include <QtNetwork>
/////// #include <QHttp>
{
Q_OBJECT
//
public:
int httpGetId;
int onlist;
/* stop declared */
GetFile()
{
}
{
onlist = process + 1;
file = new QFile(savelocalfile
);
emit ErrorGetFile
(QString("Unable to save the file %1: %2.").
arg(savelocalfile,file
->errorString
()));
delete file;
file = 0;
return;
}
http->setHost(urls.host(),80);
httpGetId = http->get(urls.path(), file);
connect(http, SIGNAL(dataReadProgress(int, int)),this, SLOT(HProgress(int, int)));
connect(http, SIGNAL(requestFinished(int, bool)),this, SLOT(httpRequestFinished(int, bool)));
}
signals:
void ReadStatus( int f , int e );
void MakeNext( int f );
public slots:
void HProgress( int full , int maked )
{
emit ReadStatus(full,maked);
}
void httpRequestFinished( int requestId, bool error )
{
if (requestId != httpGetId) {
return;
}
file->close();
if (error) {
file->remove();
emit ErrorGetFile
(QString("Download failed: %1.").
arg(http
->errorString
()));
} else {
emit MakeNext(onlist);
}
}
};
//
#endif // GETFILE_H
#ifndef GETFILE_H
#define GETFILE_H
#include <QObject>
#include <QtGui>
#include <QtNetwork>
/////// #include <QHttp>
class GetFile : public QObject
{
Q_OBJECT
//
public:
QFile *file;
QHttp *http;
int httpGetId;
int onlist;
/* stop declared */
GetFile()
{
}
void RequestFile( QString url , QString savelocalfile , int process )
{
onlist = process + 1;
QUrl urls(url);
file = new QFile(savelocalfile);
if (!file->open(QIODevice::WriteOnly)) {
emit ErrorGetFile(QString("Unable to save the file %1: %2.").arg(savelocalfile,file->errorString()));
delete file;
file = 0;
return;
}
http = new QHttp(this);
http->setHost(urls.host(),80);
httpGetId = http->get(urls.path(), file);
connect(http, SIGNAL(dataReadProgress(int, int)),this, SLOT(HProgress(int, int)));
connect(http, SIGNAL(requestFinished(int, bool)),this, SLOT(httpRequestFinished(int, bool)));
}
signals:
void ErrorGetFile( QString e );
void ReadStatus( int f , int e );
void MakeNext( int f );
public slots:
void HProgress( int full , int maked )
{
emit ReadStatus(full,maked);
}
void httpRequestFinished( int requestId, bool error )
{
if (requestId != httpGetId) {
return;
}
file->close();
if (error) {
file->remove();
emit ErrorGetFile(QString("Download failed: %1.").arg(http->errorString()));
} else {
emit MakeNext(onlist);
}
}
};
//
#endif // GETFILE_H
To copy to clipboard, switch view to plain text mode
Bookmarks