I used qftp in the qthread,but when i upload file ,I Cannot find the uploaded file and the signal code cannot be executed when debug.the following is code
Qt Code:
  1. //////////////storethread.h/////////
  2. class storescpThread:public QThread
  3. {
  4. Q_OBJECT
  5. public:
  6. storescpThread(QTextEdit *txtEdit,QObject *parent = 0);
  7. ~storescpThread();
  8. private slots:
  9. void connectOrDisconnect();
  10. void ftpListInfo(const QUrlInfo &urlInfo);
  11. void ftpCommandFinished(int commandId, bool error);
  12. void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
  13. private :
  14. QTextEdit * textEdit;
  15. QFtp *ftp;
  16. QFile *file;
  17. QStringList fileList;
  18. }
  19. /////////////////////////storethread.cxx//////////
  20. storescpThread::storescpThread(QTextEdit *txtEdit,QObject *parent): QThread(parent)
  21. {
  22. ftp=0;
  23. }
  24. void storescpThread::connectOrDisconnect()
  25. {
  26. if (ftp) {
  27. ftp->abort();
  28. ftp->deleteLater();
  29. ftp = 0;
  30. }
  31.  
  32. ftp = new QFtp(this);
  33.  
  34. //the SLOT function not be perfomed! why?
  35. [FONT="Arial Black"]connect(ftp, SIGNAL(commandFinished(int, bool)),
  36. this, SLOT(ftpCommandFinished(int, bool)));
  37. connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
  38. this, SLOT(ftpListInfo(const QUrlInfo &)));
  39. connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
  40. this, SLOT(updateDataTransferProgress(qint64, qint64)));[/FONT]
  41.  
  42. ftp->connectToHost("192.168.1.1");
  43. ftp->login("ftpuser","ftpuser");
  44. ftp->cd("/data"); //init dir
  45. fileList.clear();
  46. ftp->list();
  47. QFile file("c:\\testdata.jpg");
  48. if (!file.open(QIODevice::ReadOnly))
  49. return false;
  50. QFileInfo fi(filename);
  51. ftp->put(&file,"testtest.jpg"); //the file not be uploaded!!!!!
  52.  
  53.  
  54. }
  55. // the following SLOT not be perfomed!where is the emited message?
  56. void storescpThread::ftpCommandFinished(int, bool error)
  57. {
  58.  
  59. if (ftp->currentCommand() == QFtp::ConnectToHost) {
  60. if (error) {
  61. QMessageBox::information(0, tr("FTP"),
  62. tr("error"));
  63. return;
  64. }
  65. return;
  66. }
  67.  
  68. if (ftp->currentCommand() == QFtp::Get) {
  69.  
  70. }
  71. if (ftp->currentCommand() == QFtp::List) {
  72. QMessageBox::information(0, tr("FTP"),"LIST");
  73. }
  74. if (ftp->currentCommand() == QFtp::Put) {
  75.  
  76. }
  77. }
  78.  
  79. void storescpThread::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
  80. {
  81. }
  82.  
  83. void storescpThread::ftpListInfo(const QUrlInfo &urlInfo)
  84. {
  85. fileList<<urlInfo.name() ;
  86. }
To copy to clipboard, switch view to plain text mode