блог-форум о программировании
Вы не вошли.
Страницы 1
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui>
#include <QtWidgets>
#include <QtNetwork>
class Dialog : public QDialog {
Q_OBJECT
public:
QLineEdit *Line;
QPushButton *Button;
QProgressBar *Progress;
Dialog(QWidget *parent = 0);
~Dialog();
public slots:
void SlotGet();
void updateDataTransferProgress(qint64 readBytes, qint64 totalBytes);
};
#endif // DIALOG_H
Реализация:
#include "dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent) {
Line = new QLineEdit();
Button = new QPushButton("Get!");
Progress = new QProgressBar();
Progress->setValue(0);
Progress->hide();
QHBoxLayout *Top = new QHBoxLayout();
Top->addWidget(Line,1);
Top->addWidget(Button);
QVBoxLayout *Out = new QVBoxLayout();
Out->addLayout(Top);
Out->addWidget(Progress);
setLayout(Out);
setFixedSize(320,82);
connect(Button,SIGNAL(clicked()),this,SLOT(SlotGet()));
}
Dialog::~Dialog() {
}
void Dialog::SlotGet() {
qDebug() << "Start";
Progress->show();
QEventLoop Loop;
QNetworkAccessManager *Net = new QNetworkAccessManager(this);
QNetworkRequest Req = QNetworkRequest(Line->text());
QNetworkReply *Reply = Net->get(Req);
connect(Reply, SIGNAL(downloadProgress(qint64, qint64)), this,
SLOT(updateDataTransferProgress(qint64, qint64)));
connect(Reply, SIGNAL(finished()),&Loop, SLOT(quit()));
Loop.exec();
Progress->hide();
QUrl Url(Line->text());
QFileInfo FileInfo=Url.path();
QFile File(FileInfo.fileName());
File.open(QIODevice::WriteOnly);
File.write(Reply->readAll());
delete Reply;
}
//
// url для тестовой скачки
// http ://garr.dl.sourceforge.net/project/mingw/
// MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe
//
void Dialog::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes) {
Progress->setMaximum(totalBytes);
Progress->setValue(readBytes);
}
:: Мои программные ништяки ::
Вне форума
Страницы 1
[ Сгенерировано за 0.059 сек, 7 запросов выполнено - Использовано памяти: 2.18 Мбайт (Пик: 2.71 Мбайт) ]