I use qftp to upload a test file in qmainwindow,but failed,Even i cannot pick up the signal,I think the code is right,why?
Qt Code:
  1. ////////////////cfrmmain.h
  2. class frmMainWindow:public QMainWindow,public Ui::MainWindow
  3. {
  4. Q_OBJECT
  5. public:
  6. frmMainWindow();
  7. private:
  8.  
  9. QFtp *ftp; //连接FTP
  10. QFile *file;
  11. QStringList fileList;
  12.  
  13. private slots:
  14. void btnStartClicked();
  15. void ftpListInfo(const QUrlInfo &urlInfo);
  16. void ftpCommandFinished(int commandId, bool error);
  17. void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
  18. };
  19. /////////////////cfrmmain.cpp/////////
  20. frmMainWindow::frmMainWindow()
  21. {
  22. setupUi(this);
  23. connect(startSCP,SIGNAL(clicked()),this ,SLOT(btnStartClicked()));
  24. ftp=0;
  25. }
  26. void frmMainWindow::btnStartClicked()
  27. {
  28. if (ftp) {
  29. ftp->abort();
  30. ftp->deleteLater();
  31. ftp = 0;
  32. return;
  33. }
  34.  
  35. ftp = new QFtp;
  36. connect(ftp, SIGNAL(commandFinished(int, bool)),
  37. this, SLOT(ftpCommandFinished(int, bool)));
  38. connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
  39. this, SLOT(ftpListInfo(const QUrlInfo &)));
  40. connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
  41. this, SLOT(updateDataTransferProgress(qint64, qint64)));
  42.  
  43. ftp->connectToHost("ftp.trolltech.com");
  44. ftp->login();
  45. ftp->list();
  46.  
  47. }
  48.  
  49.  
  50. [COLOR="Red"]/////////////////all the SLOT function cannot performed ,why????????[/COLOR]
  51. void frmMainWindow::ftpCommandFinished(int, bool error)
  52. {
  53.  
  54. if (ftp->currentCommand() == QFtp::ConnectToHost) {
  55. if (error) {
  56. QMessageBox::information(0, tr("FTP"),
  57. tr("Unable to connect to the FTP server "
  58. "at %1. Please check that the host "
  59. "name is correct.")
  60. .arg("192.168.1.3"));
  61. return;
  62. }
  63. return;
  64. }
  65.  
  66. if (ftp->currentCommand() == QFtp::Get) {
  67.  
  68.  
  69. }
  70. if (ftp->currentCommand() == QFtp::List) {
  71. QMessageBox::information(0, tr("FTP"),"LIST");
  72.  
  73. }
  74. if (ftp->currentCommand() == QFtp::Put) {
  75.  
  76. }
  77. }
  78.  
  79. void frmMainWindow::updateDataTransferProgress(qint64 readBytes,
  80. qint64 totalBytes)
  81. {
  82.  
  83.  
  84. void frmMainWindow::ftpListInfo(const QUrlInfo &urlInfo)
  85. {
  86. fileList<<urlInfo.name() ;
  87. }
To copy to clipboard, switch view to plain text mode