QFtp调用list函数,listInfo没有反应

Jan_Sen 2017-06-16 10:32:22
按照网上的代码模板,用QFtp操作FTP,发现调用list()函数的时候,listInfo信号没有被emit。获取不了文件的目录和名字。其他的操作,上传下载什么的都可以的。用其他的工具访问这个FTP,所有操作都正常的。
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setValue(0);
ftp = new QFtp();
ftp->setTransferMode(QFtp::Passive);
connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int)));
connect(ftp, SIGNAL(commandFinished(int, bool)),
this, SLOT(ftpCommandFinished(int, bool)));
connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo))); //没反应
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
this, SLOT(updateDataTransferProgress(qint64, qint64)));
connect(ui->fileList, SIGNAL(itemActivated(QTreeWidgetItem*, int)),
this, SLOT(processItem(QTreeWidgetItem*, int)));
}


void MainWindow::ftpCommandFinished(int, bool error)
{
if(ftp->currentCommand() == QFtp::ConnectToHost) {
if (error) ui->label->setText(tr("连接服务器出现错误:%1").arg(ftp->errorString()));
else ui->label->setText(tr("连接到服务器成功"));
} else if (ftp->currentCommand() == QFtp::Login) {
if (error) ui->label->setText(tr("登录出现错误:%1").arg(ftp->errorString()));
else {
ui->label->setText(tr("登录成功"));
ftp->list();
}
} else if (ftp->currentCommand() == QFtp::Get) {
if(error) ui->label->setText(tr("下载出现错误:%1").arg(ftp->errorString()));
else {
ui->label->setText(tr("已经完成下载"));
file->close();
}
ui->downloadButton->setEnabled(true);
} else if (ftp->currentCommand() == QFtp::List) {
if (isDirectory.isEmpty())
{
ui->fileList->addTopLevelItem(
new QTreeWidgetItem(QStringList()<< tr("<empty>")));
ui->fileList->setEnabled(false);
ui->label->setText(tr("该目录为空"));
qDebug() << "该目录为空" << endl;
}
} else if (ftp->currentCommand() == QFtp::Close) {
ui->label->setText(tr("已经关闭连接"));
}
}


槽函数实现
void MainWindow::addToList(const QUrlInfo &urlInfo)
{
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, urlInfo.name());
item->setText(1, QString::number(urlInfo.size()));
item->setText(2, urlInfo.owner());
item->setText(3, urlInfo.group());
item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy"));
QPixmap pixmap(urlInfo.isDir() ? "../myFTP/dir.png" : "../myFTP/file.png");
item->setIcon(0, pixmap);
isDirectory[urlInfo.name()] = urlInfo.isDir();
ui->fileList->addTopLevelItem(item);
if (!ui->fileList->currentItem()) {
ui->fileList->setCurrentItem(ui->fileList->topLevelItem(0));
ui->fileList->setEnabled(true);
}
}
...全文
7230 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChampagneYo 2020-01-22
  • 打赏
  • 举报
回复
原因是QFtp类里面的parseDir函数的正则表达式与FTP服务器类型不同,需要修改这个类。
smallblacktracy 2019-08-07
  • 打赏
  • 举报
回复 1
请问楼主解决了么
LVsler 2019-08-06
  • 打赏
  • 举报
回复
请问楼主解决了么
feng_yyuan 2017-11-23
  • 打赏
  • 举报
回复
你好,我也遇到了这个问题,请问你解决了吗?可以告诉我方法吗?
Jan_Sen 2017-06-26
  • 打赏
  • 举报
回复
麻烦大神解答一下

16,173

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧