Downloading a file with Qt?

こ雲淡風輕ζ 提交于 2019-12-02 07:24:32

to download a file you need : a QNetworkAccessManager in this case http. a QFile in this case file. a QNetworkReply in this case reply connect the reply with a slot that writes the bytes received through QNetworkAccessManager in this case the slot is called readingReadyBytes()

so i create the request and connect to my slot:

 const QNetworkRequest& request = QNetworkRequest(url);
 reply = http->get(request);
 QObject::connect(reply, SIGNAL(readyRead()), this,
        SLOT( readingReadyBytes() ));

then i create my slot:

 void yourClass::readingReadyBytes() {
    file->write(reply->read(reply->bytesAvailable()));
 }

finally you have to save and close your file. tipically is done when the QNetworkAccessManager emit the finished signal.. this is what i remember and i think it is all..

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