QHttp get()下载网络图片时,文件已创建,但是为0字节

kidscannan 2011-11-30 11:09:15
代码如下:
QHttp http;

bool HttpGet::getFile(const QUrl &url,const QString filepath)
{
QFile *file;
file = new QFile(filepath);

if (!file->open(QIODevice::WriteOnly))
{
delete file;
file = 0;
return false;
}

http.setHost(url.host(), url.port(80));
http.get(url.path(),file);
http.close();

return true;
}
求解。。。。
...全文
203 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kidscannan 2011-12-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 warknife 的回复:]

qt安装完毕后 examples\network\http 下就有个范例程序,机制一样....
[/Quote]之前也想用那个例子做参考,但是我觉得只是下载图片而已,不是下什么特别大的东西,就另外参考了QHttp,看来又回到之前的方法了。不过还是要谢谢,这期间又学了不少东西,
warknife 2011-12-12
  • 打赏
  • 举报
回复
qt安装完毕后 examples\network\http 下就有个范例程序,机制一样....
kidscannan 2011-12-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ancheel 的回复:]

引用 4 楼 warknife 的回复:

原理性错误!!!!
Qhttp的get方法是非阻塞的!!!
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The func……
[/Quote]那怎样进行改进才可以正常下载呢?新手,求指教。谢谢
kidscannan 2011-12-09
  • 打赏
  • 举报
回复
somebody,anybody,help
ancheel 2011-12-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 warknife 的回复:]

原理性错误!!!!
Qhttp的get方法是非阻塞的!!!
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique id……
[/Quote]

的确如此。因为以前别人问过这问题,原因都是没把文件关了。这次粗心没细看他代码,只找看看没有有file.close()就回了。。
warknife 2011-12-09
  • 打赏
  • 举报
回复
原理性错误!!!!
Qhttp的get方法是非阻塞的!!!
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted() and requestFinished().

kidscannan 2011-12-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ancheel 的回复:]

把文件关了。
file.close();
[/Quote]还是不行,下载不是每次都失败,偶尔也会成功
ancheel 2011-11-30
  • 打赏
  • 举报
回复
把文件关了。
file.close();

21,470

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧