关于QFtp下载的问题

cwt_s cwt_s 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
主要代码:
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ftp = new QFtp(this);
ftp->connectToHost("ftp.qt.nokia.com"); //连接到服务器
ftp->login(); //登录
ftp->cd("qt"); //跳转到“qt”目录下
QFile *file = new QFile("INSTALL");
if (!file->open(QIODevice::WriteOnly))
{
delete file;
return;
}
ftp->get("INSTALL", file);
connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(ftpCommandStarted(int)));
connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(ftpCommandFinished(int,bool)));
ftp->close(); //关闭连接
}

Widget::~Widget()
{
delete ui;
}

void Widget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void Widget::ftpCommandStarted(int)
{
if(ftp->currentCommand() == QFtp::ConnectToHost)
{
ui->label->setText(tr("正在连接到服务器..."));
}

if(ftp->currentCommand() == QFtp::Login)
{
ui->label->setText(tr("正在登录..."));
}

if(ftp->currentCommand() == QFtp::Get)
{
ui->label->setText(tr("正在下载..."));
}

else if(ftp->currentCommand() == QFtp::Close)
{
ui->label->setText(tr("正在关闭连接..."));
}
}

void Widget::ftpCommandFinished(int,bool error)
{
if(ftp->currentCommand() == QFtp::ConnectToHost)
{
if(error)
ui->label->setText(tr("连接服务器出现错误:%1").arg(ftp->errorString()));
else
ui->label->setText(tr("连接到服务器成功"));
return;
}

if(ftp->currentCommand() == QFtp::Login)
{
if(error)
ui->label->setText(tr("登录出现错误:%1").arg(ftp->errorString()));
else
{
ui->label->setText(tr("登录成功"));

}
}

if(ftp->currentCommand() == QFtp::Get)
{
if(error)
ui->label->setText(tr("下载出现错误:%1").arg(ftp->errorString()));
else
{
ui->label->setText(tr("已经完成下载"));
ui->textBrowser->setText(ftp->readAll());
}
}



else if (ftp->currentCommand() == QFtp::Close)
{
ui->label->setText(tr("已经关闭连接"));
}
}



现在问题是下小的文件就下不来,大小为0,下大的文件不完整,总之就有丢失,不知怎么解决,求高人指点...谢谢,另外不是网络问题,我用QT自带的FTP例子下文件完全没问题。
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
cwt_s
Qt 21,503 成员 26,693 内容