QT에서 큰 파일을 다운로드할 때 화면이 멈추는 현상이 발생했습니다.
이를 개선하기 위한 작업으로..
1
2
3
4
5
6
|
QNetworkAccessManager* mgr = new QNetworkAccessManager();
QNetworkReply* rpy = mgr->get(request);
QObject::connect(mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
QObject::connect(rpy, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
QObject::connect(rpy, SIGNAL(QNetworkReply::errorOccurred(QNetworkReply::NetworkError*)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
|
cs |
다운로드 완료시점(finished)에
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
void UpdateManager::downloadFinished(QNetworkReply* data)
{
try
{
qDebug() << "downloadFinished!!";
QString updatePath = QString("%1/update").arg(qApp->applicationDirPath());
if (QDir(updatePath).exists() != true)
{
MakeFolder(updatePath.toStdWString().c_str());
}
_threadDownload = std::thread(&UpdateManager::downloadThread, this, data);
_threadDownload.detach();
}
catch (std::exception& e)
{
}
}
|
cs |
스레드를 만들어서 실행하면 멈춤현상이 없어진다.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
void UpdateManager::downloadThread(QNetworkReply* data)
{
QString updatePath = QString("%1/update").arg(qApp->applicationDirPath());
QFile localFile(updatePath + "/RAYFace_v" + _newVersion + "_setup.exe");
if (!localFile.open(QIODevice::WriteOnly))
return;
QByteArray ba = data->readAll();
localFile.write(ba);
localFile.close();
emit signalDownloadFinished(_newVersion);
}
|
cs |