ftpclient-example.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 937 行 · 第 1/3 页
HTML
937 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/examples/network/ftpclient/ftpclient.doc:5 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>An FTP client</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>An FTP client</h1> <p> <p> This example implements a FTP client. It uses <a href="qurloperator.html">QUrlOperator</a> (which inturn uses <a href="qftp.html">QFtp</a>) to perform its FTP commands.<p> <hr><p> The API of the FtpMainWindow class (ftpmainwindow.h):<p> <pre>/****************************************************************************** $Id: qt/ftpmainwindow.h 3.0.5 edited Oct 12 2001 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#ifndef FTPMAINWINDOW_H#define FTPMAINWINDOW_H#include <<a href="qmainwindow-h.html">qmainwindow.h</a>>#include <<a href="qurloperator-h.html">qurloperator.h</a>>class FtpView;class QSplitter;class QVBox;class QSpinBox;class QComboBox;class QLineEdit;class QNetworkOperation;class QLabel;class QProgressBar;class FtpMainWindow : public <a href="qmainwindow.html">QMainWindow</a>{ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>public: FtpMainWindow(); <a href="qsplitter.html">QSplitter</a> *mainSplitter() const { return splitter; }private: void setupLeftSide(); void setupRightSide(); void setupCenterCommandBar(); void setup();private slots: void slotLocalDirChanged( const <a href="qstring.html">QString</a> &path ); void slotLocalDirChanged( const <a href="qurlinfo.html">QUrlInfo</a> &info ); void slotRemoteDirChanged( const <a href="qstring.html">QString</a> &path ); void slotRemoteDirChanged( const <a href="qurlinfo.html">QUrlInfo</a> &info ); void slotConnect(); void slotUpload(); void slotDownload(); void slotLocalStart( <a href="qnetworkoperation.html">QNetworkOperation</a> * ); void slotLocalFinished( <a href="qnetworkoperation.html">QNetworkOperation</a> * ); void slotRemoteStart( <a href="qnetworkoperation.html">QNetworkOperation</a> * ); void slotRemoteFinished( <a href="qnetworkoperation.html">QNetworkOperation</a> * ); void slotLocalDataTransferProgress( int, int, QNetworkOperation * ); void slotRemoteDataTransferProgress( int, int, QNetworkOperation * ); void slotLocalMkDir(); void slotLocalRemove(); void slotRemoteMkDir(); void slotRemoteRemove(); void slotConnectionStateChanged( int, const <a href="qstring.html">QString</a> &msg );private: <a href="qsplitter.html">QSplitter</a> *splitter; <a href="qvbox.html">QVBox</a> *mainWidget; FtpView *leftView, *rightView; <a href="qcombobox.html">QComboBox</a> *localCombo, *remoteHostCombo, *remotePathCombo, *userCombo; <a href="qlineedit.html">QLineEdit</a> *passLined; <a href="qspinbox.html">QSpinBox</a> *portSpin; <a href="qurloperator.html">QUrlOperator</a> localOperator, remoteOperator, oldLocal, oldRemote; <a href="qlabel.html">QLabel</a> *progressLabel1, *progressLabel2; <a href="qprogressbar.html">QProgressBar</a> *progressBar1, *progressBar2;};#endif</pre><p> <hr><p> The Implementation of the FtpMainWindow class (ftpmainwindow.cpp):<p> <pre>/****************************************************************************** $Id: qt/ftpmainwindow.cpp 3.0.5 edited Oct 12 2001 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "ftpmainwindow.h"#include "ftpview.h"#include <<a href="qvbox-h.html">qvbox.h</a>>#include <<a href="qhbox-h.html">qhbox.h</a>>#include <<a href="qsplitter-h.html">qsplitter.h</a>>#include <<a href="qcombobox-h.html">qcombobox.h</a>>#include <<a href="qlabel-h.html">qlabel.h</a>>#include <<a href="qspinbox-h.html">qspinbox.h</a>>#include <<a href="qlineedit-h.html">qlineedit.h</a>>#include <<a href="qpushbutton-h.html">qpushbutton.h</a>>#include <<a href="qmessagebox-h.html">qmessagebox.h</a>>#include <<a href="qprogressbar-h.html">qprogressbar.h</a>>#include <<a href="qdir-h.html">qdir.h</a>>#include <<a href="qinputdialog-h.html">qinputdialog.h</a>>#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qstatusbar-h.html">qstatusbar.h</a>><a name="f262"></a>FtpMainWindow::FtpMainWindow() : <a href="qmainwindow.html">QMainWindow</a>(), localOperator( "/" ){ setup(); // connect to the signals of the local QUrlOperator - this will be used to // work on the local file system (listing dirs, etc.) and to copy files // TO the local filesystem (downloading) <a href="qobject.html#connect">connect</a>( &localOperator, SIGNAL( newChildren( const <a href="qvaluelist.html">QValueList</a><QUrlInfo> &, QNetworkOperation * ) ), leftView, SLOT( slotInsertEntries( const <a href="qvaluelist.html">QValueList</a><QUrlInfo> & ) ) ); <a href="qobject.html#connect">connect</a>( &localOperator, SIGNAL( start( <a href="qnetworkoperation.html">QNetworkOperation</a> * ) ), this, SLOT( slotLocalStart( <a href="qnetworkoperation.html">QNetworkOperation</a> *) ) ); <a href="qobject.html#connect">connect</a>( &localOperator, SIGNAL( finished( <a href="qnetworkoperation.html">QNetworkOperation</a> * ) ), this, SLOT( slotLocalFinished( <a href="qnetworkoperation.html">QNetworkOperation</a> *) ) ); <a href="qobject.html#connect">connect</a>( leftView, SIGNAL( itemSelected( const <a href="qurlinfo.html">QUrlInfo</a> & ) ), this, SLOT( slotLocalDirChanged( const <a href="qurlinfo.html">QUrlInfo</a> & ) ) ); <a href="qobject.html#connect">connect</a>( &localOperator, SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ), this, SLOT( slotLocalDataTransferProgress( int, int, QNetworkOperation * ) ) ); // connect to the signals of the remote QUrlOperator - this will be used to // work on the remote file system (on the FTP Server) and to copy files // TO the ftp server (uploading) <a href="qobject.html#connect">connect</a>( &remoteOperator, SIGNAL( newChildren( const <a href="qvaluelist.html">QValueList</a><QUrlInfo> &, QNetworkOperation * ) ), rightView, SLOT( slotInsertEntries( const <a href="qvaluelist.html">QValueList</a><QUrlInfo> & ) ) ); <a href="qobject.html#connect">connect</a>( &remoteOperator, SIGNAL( start( <a href="qnetworkoperation.html">QNetworkOperation</a> * ) ), this, SLOT( slotRemoteStart( <a href="qnetworkoperation.html">QNetworkOperation</a> *) ) ); <a href="qobject.html#connect">connect</a>( &remoteOperator, SIGNAL( finished( <a href="qnetworkoperation.html">QNetworkOperation</a> * ) ), this, SLOT( slotRemoteFinished( <a href="qnetworkoperation.html">QNetworkOperation</a> *) ) ); <a href="qobject.html#connect">connect</a>( rightView, SIGNAL( itemSelected( const <a href="qurlinfo.html">QUrlInfo</a> & ) ), this, SLOT( slotRemoteDirChanged( const <a href="qurlinfo.html">QUrlInfo</a> & ) ) ); <a href="qobject.html#connect">connect</a>( &remoteOperator, SIGNAL( dataTransferProgress( int, int, QNetworkOperation * ) ), this, SLOT( slotRemoteDataTransferProgress( int, int, QNetworkOperation * ) ) ); <a href="qobject.html#connect">connect</a>( &remoteOperator, SIGNAL( connectionStateChanged( int, const <a href="qstring.html">QString</a> & ) ), this, SLOT( slotConnectionStateChanged( int, const <a href="qstring.html">QString</a> & ) ) ); // read the local filesystem at the beginning once localOperator.listChildren(); // create status bar (void)<a href="qmainwindow.html#statusBar">statusBar</a>();}void <a name="f263"></a>FtpMainWindow::setupLeftSide(){ // Setup the left side of the GUI, this is the listview // of the local filesystem <a href="qvbox.html">QVBox</a> *layout = new <a href="qvbox.html">QVBox</a>( splitter );<a name="x656"></a> layout-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 );<a name="x655"></a> layout-><a href="qframe.html#setMargin">setMargin</a>( 5 ); <a href="qhbox.html">QHBox</a> *h = new <a href="qhbox.html">QHBox</a>( layout ); h-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); <a href="qlabel.html">QLabel</a> *l = new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( "Local Path:" ), h );<a name="x686"></a><a name="x659"></a> l-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( l-><a href="qwidget.html#sizeHint">sizeHint</a>().width() ); localCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, h );<a name="x652"></a> localCombo-><a href="qcombobox.html#insertItem">insertItem</a>( "/" );<a name="x650"></a> <a href="qobject.html#connect">connect</a>( localCombo, SIGNAL( <a href="qcombobox.html#activated">activated</a>( const <a href="qstring.html">QString</a> & ) ), this, SLOT( slotLocalDirChanged( const <a href="qstring.html">QString</a> & ) ) ); leftView = new FtpView( layout ); <a href="qhbox.html">QHBox</a> *bottom = new <a href="qhbox.html">QHBox</a>( layout ); bottom-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); <a href="qpushbutton.html">QPushButton</a> *bMkDir = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "New Directory" ), bottom ); <a href="qpushbutton.html">QPushButton</a> *bRemove = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "Remove" ), bottom );<a name="x649"></a> <a href="qobject.html#connect">connect</a>( bMkDir, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotLocalMkDir() ) ); <a href="qobject.html#connect">connect</a>( bRemove, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotLocalRemove() ) );<a name="x678"></a> splitter-><a href="qsplitter.html#setResizeMode">setResizeMode</a>( layout, QSplitter::Stretch );}void <a name="f264"></a>FtpMainWindow::setupRightSide(){ // Setup the right side of the GUI, this is the listview // of the remote filesystem (FTP), needs also lineedits/combos // for username, password, etc. <a href="qvbox.html">QVBox</a> *layout = new <a href="qvbox.html">QVBox</a>( splitter ); layout-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); layout-><a href="qframe.html#setMargin">setMargin</a>( 5 ); <a href="qhbox.html">QHBox</a> *h = new <a href="qhbox.html">QHBox</a>( layout ); h-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); <a href="qlabel.html">QLabel</a> *l = new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( "Remote Host:" ), h ); l-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( l-><a href="qwidget.html#sizeHint">sizeHint</a>().width() ); remoteHostCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, h ); l = new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( "Port:" ), h ); l-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( l-><a href="qwidget.html#sizeHint">sizeHint</a>().width() ); portSpin = new <a href="qspinbox.html">QSpinBox</a>( 0, 32767, 1, h );<a name="x675"></a> portSpin-><a href="qspinbox.html#setValue">setValue</a>( 21 );<a name="x676"></a> portSpin-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( portSpin-><a href="qwidget.html#sizeHint">sizeHint</a>().width() );<a name="x677"></a> remoteOperator.setPort( portSpin-><a href="qspinbox.html#value">value</a>() ); h = new <a href="qhbox.html">QHBox</a>( layout ); h-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); l = new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( "Remote Path:" ), h ); l-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( l-><a href="qwidget.html#sizeHint">sizeHint</a>().width() ); remotePathCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, h ); h = new <a href="qhbox.html">QHBox</a>( layout ); h-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); l = new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( "Username:" ), h ); l-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( l-><a href="qwidget.html#sizeHint">sizeHint</a>().width() ); userCombo = new <a href="qcombobox.html">QComboBox</a>( TRUE, h ); l = new <a href="qlabel.html">QLabel</a>( <a href="qobject.html#tr">tr</a>( "Password:" ), h ); l-><a href="qwidget.html#setFixedWidth">setFixedWidth</a>( l-><a href="qwidget.html#sizeHint">sizeHint</a>().width() ); passLined = new <a href="qlineedit.html">QLineEdit</a>( h );<a name="x660"></a> passLined-><a href="qlineedit.html#setEchoMode">setEchoMode</a>( QLineEdit::Password ); rightView = new FtpView( layout ); <a href="qhbox.html">QHBox</a> *bottom = new <a href="qhbox.html">QHBox</a>( layout ); bottom-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); <a href="qpushbutton.html">QPushButton</a> *bMkDir = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "New Directory" ), bottom ); <a href="qpushbutton.html">QPushButton</a> *bRemove = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "Remove" ), bottom ); <a href="qobject.html#connect">connect</a>( bMkDir, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotRemoteMkDir() ) ); <a href="qobject.html#connect">connect</a>( bRemove, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotRemoteRemove() ) ); splitter-><a href="qsplitter.html#setResizeMode">setResizeMode</a>( layout, QSplitter::Stretch ); <a href="qobject.html#connect">connect</a>( remotePathCombo, SIGNAL( <a href="qcombobox.html#activated">activated</a>( const <a href="qstring.html">QString</a> & ) ), this, SLOT( slotRemoteDirChanged( const <a href="qstring.html">QString</a> & ) ) );}void <a name="f265"></a>FtpMainWindow::setupCenterCommandBar(){ // Setup the command bar in the middle between the two views <a href="qvbox.html">QVBox</a> *w = new <a href="qvbox.html">QVBox</a>( splitter ); splitter-><a href="qsplitter.html#setResizeMode">setResizeMode</a>( w, QSplitter::FollowSizeHint ); w-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); w-><a href="qframe.html#setMargin">setMargin</a>( 5 ); <a href="qpushbutton.html">QPushButton</a> *bConnect = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "&Connect" ), w ); (void)new <a href="qwidget.html">QWidget</a>( w ); <a href="qpushbutton.html">QPushButton</a> *bUpload = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "== &Upload ==>" ), w ); <a href="qpushbutton.html">QPushButton</a> *bDownload = new <a href="qpushbutton.html">QPushButton</a>( <a href="qobject.html#tr">tr</a>( "<== &Download ==" ), w ); (void)new <a href="qwidget.html">QWidget</a>( w ); <a href="qobject.html#connect">connect</a>( bConnect, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotConnect() ) ); <a href="qobject.html#connect">connect</a>( bUpload, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotUpload() ) ); <a href="qobject.html#connect">connect</a>( bDownload, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotDownload() ) );}void <a name="f266"></a>FtpMainWindow::setup(){ // Setup the GUI mainWidget = new <a href="qvbox.html">QVBox</a>( this ); splitter = new <a href="qsplitter.html">QSplitter</a>( mainWidget ); setupLeftSide(); setupCenterCommandBar(); setupRightSide();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?