Downloading File in Qt From URL

后端 未结 3 869
半阙折子戏
半阙折子戏 2020-12-31 17:43

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

3条回答
  •  耶瑟儿~
    2020-12-31 18:02

    • You're using uninitialized pointer, so it points out to nowhere. Initialize reply with NULL in your constructor.
    • You should connect 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.

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

提交回复
热议问题