PDA

View Full Version : Finding filename from QNetworkReply



Valheru
17th August 2008, 21:15
I am implementing an embedded browser using QWebView in a program, and I am trying to handle the downloading of files. I have everything set up, the files are being downloaded and everything is working as I want it. The only thing I can't figure out is how to find out the filename of the data being downloaded. The filename is generated (almost always) by the servers dynamically when you click on a button or icon. I am getting the data fine in a QNetworkReply, by hooking up to it's finished() signal.
How do you get the filename the data was sent with? Must you use QNetworkReply, QNetworkRequest or QNetworkManager? I've been debugging just about every attribute of all three classes and I can't find the filename.

TIA,
Valheru.

jacek
17th August 2008, 23:15
Check QNetworkReply::rawHeaderList() and then use QNetworkReply::header() or QNetworkReply::rawHeader().

Valheru
18th August 2008, 07:43
I had been debugging those very functions :p One would expect QNetworkReply::header( QNetworkRequest::LocationHeader) (http://doc.trolltech.com/latest/qnetworkreply.html#header) to contain the filename, but it doesn't. Very infrequently some servers send the filename in QNetworkReply::header( QNetworkRequest::ContentTypeHeader) (http://doc.trolltech.com/latest/qnetworkreply.html#header)
You can, however, reliably retrieve the filename in this case by getting the raw header for Content-Disposition, using QNetworkReply::rawHeader( Content-Disposition ) (http://doc.trolltech.com/latest/qnetworkreply.html#rawHeader), which returns something along the lines of attachment; filename="filename"

xeento
24th April 2009, 10:29
Can you provide a code how did you do that? I haven't found on net any working examples how to override QNetworkReply in conjunction with QNetworkAccessManager. Thnks