1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
void Dialog_about::get_file()
{
m_file = new QFile("C:/temp/temp0/my_file.zip");
ftp = new QNetworkAccessManager();
QUrl url("ftp://ftp.clust.............../my_file.zip");
url.setUserName("user");
url.setPassword("pass");
url.setPort(21);
QNetworkRequest req(url);
reply = ftp->get(req);
connect(reply, &QNetworkReply::readyRead, this, &Dialog_about::onReadyRead);
connect(reply, &QNetworkReply::downloadProgress, this, &Dialog_about::onUpdateProgress);
connect(ftp, &QNetworkAccessManager::finished, this, &Dialog_about::onReply);
}
//----------------------------------------------------------------------------------------------
void Dialog_about::showEvent(QShowEvent * event )
{
if (!View) save_picture(install_path(true)+"/TW_about_picture.png");
QDialog::showEvent(event);
}
//----------------------------------------------------------------------------------------------
void Dialog_about::onReply(QNetworkReply* reply)
{
if (reply->error() == QNetworkReply::NoError) {
qDebug() << "Reply ok\n";
m_file->flush();
m_file->close();
}
else {
qDebug() << "Reply failed\n";
m_file->remove();
}
delete m_file;
reply->deleteLater();
}
void Dialog_about::onUpdateProgress(qint64 bytesReceived, qint64 bytesTotal)
{
qDebug() << bytesReceived << bytesTotal;
}
void Dialog_about::onReadyRead()
{
qDebug() << "File read\n";
if (m_file) {
m_file->write(reply->readAll());
}
} |
Partager