QNetworkAccessManager::put - QIODevice::read:向ftp服务器发送文件后设备未



当我向ftp服务器发送文件时,我收到QIODevice::read:设备未打开(发送此文件后..)

输出如下:

上传1673 of 1673

QIODevice::read: device not open

完成

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问题。我有同样的警告后ftp上传与qt 5.3赢vs2010。

最新更新