VS2015+QT5.9.6使用QFTP实现数据的预览和下载功能

@ [TOC](这里写自定义目录标题)

#VS2015 + QT5.9.6 msvc32位编译的QFTP库文件和实例修改了源码下的实例实现预览和下载功能

在这里插入图片描述

为了使用方便直接修改了原始码下的测试代码

MainWindow.h
#pragma once

#include <QWidget>
#include <QDialog>
#include <QHash>

QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QFile;
class QFtp;
class QLabel;
class QLineEdit;
class QTreeWidget;
class QTreeWidgetItem;
class QProgressDialog;
class QPushButton;
class QUrlInfo;
QT_END_NAMESPACE
namespace Ui {
    class CMainWindow; };
class CMainWindow : public QWidget
{
   
	Q_OBJECT

public:
	CMainWindow(QWidget *parent = Q_NULLPTR);
	~CMainWindow();
	private slots:
	//处理连接断开事件
	void connectOrDisconnect();
	void downloadFile();
	void cancelDownload();
	//连接ftp服务器
	void connectToFtp();
	void ftpCommandFinished(int commandId, bool error);
	void addToList(const QUrlInfo &urlInfo);
	void processItem(QTreeWidgetItem *item, int column);
	void cdToParent();
	void updateDataTransferProgress(qint64 readBytes,
		qint64 totalBytes);
	void enableDownloadButton();
private:
	Ui::CMainWindow *ui;
	QLabel *ftpServerLabel;
	QLineEdit *ftpServerLineEdit;
	QLabel *statusLabel;
	QTreeWidget *fileList;
	QPushButton *cdToParentButton;
	QPushButton *connectButton;
	QPushButton *downloadButton;
	QPushButton *quitButton;
	QDialogButtonBox *buttonBox;
	QProgressDialog *progressDialog;
	QHash<QString, bool> isDirectory;
	QString currentPath;
	QFtp *ftp;
	QFile *file;
};

MainWindow.cpp
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "qftp.h"
#include "qurlinfo.h"
#include <QtNetwork>
#include <QLabel>
#include <QLineEdit>
#include <QTreeWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include <QProgressDialog>
#include <QDialogButtonBox>
#include <QMessageBox>
CMainWindow::CMainWindow(QWidget *parent)
	: QWidget(parent)
	,ftp(NULL)
{
   
	ui = new Ui::CMainWindow();
	ui->setupUi(this);
	ftpServerLabel = new QLabel(tr("Ftp &server:"));
	ftpServerLineEdit = new QLineEdit("10.10.7.222");
	ftpServerLabel->setBuddy(ftpServerLineEdit);
	statusLabel = new QLabel(tr("Please enter the name of an FTP server."));

	fileList = new QTreeWidget;
	fileList->setEnabled(false);
	fileList->setRootIsDecorated(false);
	fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);
	fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time"));
	fileList->header(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值