关于QFtp下载的问题

cwt_s 2012-05-15 05:39:09
主要代码:
#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例子下文件完全没问题。
...全文
302 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shen_wei 2012-05-16
  • 打赏
  • 举报
回复
参考 Qt的例子

examples ->network ->qftp
自己对照看看。。。。
cwt_s 2012-05-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
try to use ftp binary mode
[/Quote]
本人刚学...请问具体该怎么做
儿大不由爷 2012-05-15
  • 打赏
  • 举报
回复
try to use ftp binary mode

16,211

社区成员

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

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