In my program I need to download a file, and I came across this article:
http://www.java2s.com/Code/Cpp/Qt/DownloadfromURL.htm
This code does work but it d
reply
with NULL
in your constructor.reply
after it was created (reply = manager.get(...)
), not inside of your constructor.QNetworkReply
is never deleted by QNetworkManager
as docs say:Do not delete the reply object in the slot connected to this signal. Use deleteLater().
So you shouldn't call delete on QNetworkReply
in finished
slot.
finished
slot setting data
to 0
will only set parameter value to 0
, not your class member reply
. It's an unneeded line of code. You should set your reply
member to NULL
instead.Also you should consider writing to a file every time you get data chunk, as whole file will be buffered in memory in your current case. It may lead to huge memory usage of your software when file at pointed URL is big.