您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > QT程序FTP服务器
QT程序FTP服务器12级电子新能源本2班20120553049张恒一、QT简介QT是一个跨平台的C++图形化用户界面的应用程序开发框架。它既可以开发GUI程序,也用于开发非GUI程序,比如控制台工具和服务器。在QTCreator3.1.0正式发布后,QT实现了对IOS、Android、WP的全面支持。二、FTP服务器FTP是文件传输协议的英文简称,用于Internet上的控制文件的双向传输。同多数Internet服务器一样,FTP也是分为两部分,即客户端程序与服务器系统。本次所做出的图形化界面程序为FTP的客户端程序。三、程序介绍1.UI介绍FTP客户端程序的UI界面是图所示,在UI中主要由连接、上传、下载、退出、返回、FTP地址、用户名、密码等组成,并且在下方留出大窗口用于显示FTP服务器中的文件。2.程序源代码介绍3.#includeftp.h4.#includeui_ftp.h5.6.Ftp::Ftp(QWidget*parent)7.:QWidget(parent),ui(newUi::Ftp),ftpobj(0)8.{9.ui-setupUi(this);10.//ui-lineEdit-setText(ftp.trolltech.com);11.//ui-comboBox-addItem(192.168.1.253);12.ui-lineEdit_3-setEchoMode(QLineEdit::Password);13.//ui-treeWidget-setAcceptDrops(true);14.this-setAcceptDrops(true);15.//model=newQDirModel;16.//ui-treeView-setModel(model);17.//ui-treeView-setAcceptDrops(true);18.19.ui-label_2-setText(tr(PleaseenterthenameofanFTPserver.));20.ui-lineEdit_2-setText();21.ui-lineEdit_3-setText();22.23.ui-treeWidget-setEnabled(false);24.ui-treeWidget-setRootIsDecorated(false);25.//ui-treeWidget-setHeaderLabels(QStringList()tr(Name)tr(Size)tr(Owner)tr(Group)tr(Time));26.ui-treeWidget-header()-setStretchLastSection(false);27.28.ui-pushButton_2-setDefault(true);29.ui-pushButton-setEnabled(false);30.ui-radioButton_2-setChecked(true);31.ui-pushButton_3-setEnabled(false);32.progressDialog=newQProgressDialog(this);33.34.connect(ui-checkBox,SIGNAL(clicked()),this,SLOT(enableCheckBox()));35.connect(ui-treeWidget,SIGNAL(itemActivated(QTreeWidgetItem*,int)),36.this,SLOT(processItem(QTreeWidgetItem*,int)));37.connect(ui-treeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),38.this,SLOT(enableDownloadButton()));39.connect(progressDialog,SIGNAL(canceled()),this,SLOT(cancelDownload()));40.connect(ui-pushButton_2,SIGNAL(clicked()),this,SLOT(connectOrDisconnect()));41.connect(ui-pushButton,SIGNAL(clicked()),this,SLOT(cdToParent()));42.connect(ui-pushButton_3,SIGNAL(clicked()),this,SLOT(downloadFile()));43.connect(ui-pushButton_4,SIGNAL(clicked()),this,SLOT(close()));44.connect(ui-pushButton_5,SIGNAL(clicked()),this,SLOT(uploadFile()));45.//红色代码用于设置信号槽,定义了PushButton、PushButton_2、PushButton_3等按钮的使用46.setWindowTitle(tr(FTP));47.}48.49.Ftp::~Ftp()50.{51.deleteui;52.}53.54.55.QSizeFtp::sizeHint()const56.{57.returnQSize(500,300);58.}59.60.//![0]61.voidFtp::connectOrDisconnect()62.{63.if(!ui-checkBox-isChecked()){64.if(ui-lineEdit_2-text().isEmpty()||ui-lineEdit_3-text().isEmpty())65.{66.QMessageBox::information(this,tr(FTP),tr(请检查ftp账号信息,用户名和密码都不允许为空。));67.return;68.}69.}70.//上述代码用来判断用户输入的用户名与密码是否可以登录ftp服务器71.72.if(ftpobj){73.ftpobj-abort();74.ftpobj-deleteLater();75.ftpobj=0;76.//![0]77.ui-lineEdit_2-setEnabled(true);78.ui-lineEdit_3-setEnabled(true);79.ui-checkBox-setEnabled(true);80.ui-treeWidget-setEnabled(false);81.ui-pushButton-setEnabled(false);82.ui-pushButton_3-setEnabled(false);83.ui-pushButton_2-setEnabled(true);84.ui-pushButton_2-setText(tr(Connect));85.ui-comboBox-setEditable(true);86.ui-checkBox-setChecked(false);87.#ifndefQT_NO_CURSOR88.setCursor(Qt::ArrowCursor);89.#endif90.return;91.}92.93.#ifndefQT_NO_CURSOR94.setCursor(Qt::WaitCursor);95.#endif96.97.ui-comboBox-setEditable(false);98.ui-lineEdit_2-setEnabled(false);99.ui-lineEdit_3-setEnabled(false);100.ui-checkBox-setEnabled(false);101.ui-treeWidget-setEnabled(true);102.ui-pushButton_2-setEnabled(false);103.104.//![1]105.ftpobj=newQFtp(this);106.107.connect(ftpobj,SIGNAL(commandFinished(int,bool)),108.this,SLOT(ftpCommandFinished(int,bool)));109.connect(ftpobj,SIGNAL(listInfo(constQUrlInfo&)),110.this,SLOT(addToList(constQUrlInfo&)));111.connect(ftpobj,SIGNAL(dataTransferProgress(qint64,qint64)),112.this,SLOT(updateDataTransferProgress(qint64,qint64)));113.114.ui-treeWidget-clear();115.currentPath.clear();116.isDirectory.clear();117.//![1]118.119.//![2]120.QUrlurl(ui-comboBox-currentText());121.if(!url.isValid()||url.scheme().toLower()!=QLatin1String(ftp)){122.ftpobj-connectToHost(ui-comboBox-currentText(),21);123.if(ui-checkBox-isChecked())124.ftpobj-login();125.else126.ftpobj-login(ui-lineEdit_2-text(),ui-lineEdit_3-text());127.}else{128.ftpobj-connectToHost(url.host(),url.port(21));129.130./*if(!url.userName().isEmpty())131.//ftpobj-login(QUrl::fromPercentEncoding(url.userName().toLatin1()),url.password());132.ftpobj-login(company,123456);133.else134.ftpobj-login(company,123456);*/135.136.if(ui-checkBox-isChecked())137.ftpobj-login();138.else139.ftpobj-login(ui-lineEdit_2-text(),ui-lineEdit_3-text());140.141.if(!url.path().isEmpty())142.ftpobj-cd(url.path());143.}144.if(ui-radioButton_2-isChecked())145.ftpobj-setTransferMode(QFtp::Active);146.else147.ftpobj-setTransferMode(QFtp::Passive);148.//![2]149.150.ui-label_2-setText(tr(ConnectingtoFTPserver%1...)151..arg(ui-comboBox-currentText()));152.153.}154.155.//![3]156.voidFtp::downloadFile()157.{158.QStringfileNam=ui-treeWidget-currentItem()-text(0);159.//![3]160.
本文标题:QT程序FTP服务器
链接地址:https://www.777doc.com/doc-2854641 .html