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 下就有个范例程序,机制一样....