当我向ftp服务器发送文件时,我收到消息QIODevice :: read:设备未打开(发送此文件后...)
输出如下:
上载1673年的1673
QIODevice :: read:设备未打开
完成0
#include "uploader.h"
Uploader::Uploader(QObject *parent) :
QObject(parent)
{
}
void Uploader::start(const QString &fileName) {
QUrl url("ftp://adresIP/test/tt.txt");
url.setUserName("ftp@domena.pl");
url.setPassword("passwd");
file = new QFile(fileName);
QByteArray putData;
file->open(QIODevice::ReadOnly);
putData.append(file->readAll());
//-- other attempts
file->flush();
file->close();
delete file;
//--
reply = nam.put(QNetworkRequest(url), putData);
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64)));
connect(reply, SIGNAL(finished()), this, SLOT(uploadDone()));
}
void Uploader::uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
qDebug() << "Uploaded" << bytesSent << "of" << bytesTotal;
}
void Uploader::uploadDone() {
qDebug() << "Finished" << reply->error();
reply->deleteLater();
}
//uploader.h
QNetworkAccessManager nam;
QFile *file;
QNetworkReply *reply;
//main.cpp
Uploader u;
u.start("F:\\song.mp3");
修改
我在Qt 5.0.1上进行了测试,在Ubuntu上(在它之前是Windows,Qt 5.3),在这里它的一切正常(消息QIODevice::read: device not open
没有显示..)。它可能是Qt Framework的错误?
答案 0 :(得分:1)
我认为这是一个qt问题。在ftp上传wirh qt 5.3 win vs2010之后,我收到了相同的警告。安装5.5后,消息消失了。