首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Qt (QFtp)问题

Qt (QFtp)问题
EN

Stack Overflow用户
提问于 2010-01-18 20:28:03
回答 1查看 2.3K关注 0票数 0

您好,我正在学习qt,并尝试使用QFtp上传文件,我写了以下代码

代码语言:javascript
复制
this->connect(this->ftp, SIGNAL(done(bool)), this, SLOT(ftpDone(bool)));
this->connect(this->ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(dataTransferProgress(qint64, qint64)));
this->connect(this->ftp, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));

.

代码语言:javascript
复制
if(this->file.open(QIODevice::ReadWrite))
{
    this->ftp->setTransferMode(QFtp::Active);
    this->ftp->connectToHost(this->settings->getHost());
    this->ftp->login(this->settings->getUser(), this->settings->getPassword());
    this->ftp->cd(remoteFilePath);
    this->ftp->get(this->fileName, &this->file);
    this->ftp->close();
}

它会停止,在dataTransferProgress中报告它在0/XXX,但插槽再也不会被调用(使用相同的代码,但使用get函数,我可以下载文件,并且它工作起来没有问题),而且我在超时后得到的错误是QFtp::UnknownError错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-01-18 20:46:32

假设get之前的所有命令都成功了,那么很可能是在get完成之前关闭了连接。您应该保存由get返回的标识符,并在使用该标识符调用close信号时调用commandFinished

注意:除了setTransferMode之外,您使用的所有方法都是异步的。它们将按照它们被调用的顺序执行,但由于您没有执行任何错误检查,其中一个可能会失败,其余的仍将尝试,这可能会导致一些混乱。

正确的方法是首先执行connectToHost,如果成功(可以使用commandFinished信号跟踪),则调用login等。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2085962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档