@ [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(