Qt Download File - QNetworkAccessManager, not getting data

99封情书 提交于 2019-11-29 15:43:26

The only problem I see in your code is you are not waiting for the download to be finished. The NetworkRequest object would be destructed at the end of function call.

So, I would rewrite Do_Download like this (QEventLoop syncronizes the network request):

void DownloadManager::Do_Download() {
    QEventLoop eventLoop;
    QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
    QUrl url(install_mirror); //istall_mirror is the URL provided by user
    QNetworkRequest req(url);

    QNetworkReply *reply = netManager->get(req);

    connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
    eventLoop.exec();

    writeData(reply);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!