当前位置: 代码迷 >> QT开发 >> QHttp get()下载网络图片时,文件已创建,但是为0字节,该如何处理
  详细解决方案

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

热度:153   发布时间:2016-04-25 05:06:48.0
QHttp get()下载网络图片时,文件已创建,但是为0字节
代码如下:
  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;
}
求解。。。。

------解决方案--------------------
原理性错误!!!!
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().


------解决方案--------------------
qt安装完毕后 examples\network\http 下就有个范例程序,机制一样....