1

I am working on Qt browser(code taken from Qt Tab Browser Example). This Qt browser successfully downloads an image file, but not an excel/pdf file. I need to download an excel/pdf file as attachment on click of a button. Excel generation code at back-end uses PHPExcel to generate and finally saves it using 'php://output'. On browser side, when I read through QNetworkReply's 'readAll()' function, some encoded string '��ࡱ�' gets printed and nothing gets saved in QFile object, totally empty file.

How do I get the desired excel file from this encoded string ? Please, any help. It is Linux OS and I use LibreOffice if it matters.

4

1 回答 1

1

Well, got the answer. I was printing QNetworkReply object's content on the console using reply->readAll() before reading it into the file and Qt documentation states that:

QNetworkReply is a sequential-access QIODevice, which means that once data is read from the object, it no longer kept by the device.

Therefore, i ended up with an empty file. Found this when i printed the size of the 'reply' object. Also, found some eventLoop related help from here(Roozbeh's answer).

Hope it helps someone else as well. Thanks SO !

于 2015-04-15T10:33:59.360 回答