Downloading a file with Qt?

前端 未结 1 1148
粉色の甜心
粉色の甜心 2021-01-24 12:29

I am trying to figure out a way for my Qt browser app can download a word document from our web app. The web app is written in ExtJS, when (in a browser such as Chrome) a user c

相关标签:
1条回答
  • 2021-01-24 12:56

    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..

    0 讨论(0)
提交回复
热议问题