gpt4 book ai didi

qt - QNetworkAccessManager::put - QIODevice::read:将文件发送到 ftp 服务器后设备未打开

转载 作者:行者123 更新时间:2023-12-04 16:36:38 24 4
gpt4 key购买 nike

当我将文件发送到 ftp 服务器时,我收到消息 QIODevice::read: device not open (after sent this file..)

输出看起来像这样:

Uploaded 1673 of 1673

QIODevice::read: device not open

Finished 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");

编辑:

我在 Ubuntu(之前是 Windows,Qt 5.3)上对 Qt 5.0.1 进行了测试,这里一切正常(未显示消息 QIODevice::read: device not open。 .).可能是 Qt Framework 错误?

最佳答案

我觉得是qt的问题。在 ftp 上传 wirh qt 5.3 win vs2010 后,我收到了同样的警告。安装 5.5 后,消息消失了。

关于qt - QNetworkAccessManager::put - QIODevice::read:将文件发送到 ftp 服务器后设备未打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25488099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com