Results 1 to 16 of 16

Thread: why the qftp failed in qmainwindow?where is its signal?

  1. #1
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default why the qftp failed in qmainwindow?where is its signal?

    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 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Because your slots are all private.
    You use private slots only if signals from the same class are connected to them. Otherwise use protected or public slots.

  3. #3
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    no,it's maybe not right.In the demo of QT examples\FTP, its slot is private and it works well. I rewrite the code and moved the private slot to public slot. it's just the same ,not work.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Does it execute the btnStartClicked slot when you click the button?
    Also, check the console, often Qt leaves some messages when something goes wrong.

    If btnStartClicked is not called, then you ftp object is not created.

  5. #5
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    yes,it executed.But the console reports nothing!

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Well, the only difference between your code and the ftp example is that the ftp object is created with a parent (this ). But I do not believe this is the reason.= your slots don't get called.

    Can you post your moc_cfrmain.cpp? We can see there if the signals are mapped correctly.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Quote Originally Posted by marcel View Post
    You use private slots only if signals from the same class are connected to them.
    There's nothing wrong in connecting non-local signals to private slots.

    Quote Originally Posted by cxl2253 View Post
    yes,it executed.But the console reports nothing!
    Make sure your application is compiled in debug mode (on windows you will also have to add CONFIG += console to your .pro file).

    Also check whether all connect() statements return true.

  8. #8
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    yes,my compiler flag is MDD. But i donot understand what's wrong with the code.I even want to give up qt, why there are so many problem?

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    I just tested your code and it works.

    The header:
    Qt Code:
    1. #ifndef FTP3_H
    2. #define FTP3_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_ftp3.h"
    6. #include <QUrlInfo>
    7.  
    8. class QFtp;
    9. class QFile;
    10.  
    11. class ftp3 : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. ftp3(QWidget *parent = 0, Qt::WFlags flags = 0);
    17. ~ftp3();
    18.  
    19. private:
    20. Ui::ftp3Class ui;
    21. QFtp *ftp;
    22. QFile *file;
    23. QStringList fileList;
    24. private slots:
    25. void ftpListInfo(const QUrlInfo &urlInfo);
    26. void ftpCommandFinished(int commandId, bool error);
    27. void updateDataTransferProgress(qint64 readBytes,qint64 totalBytes);
    28. };
    29.  
    30. #endif // FTP3_H
    To copy to clipboard, switch view to plain text mode 

    The cpp:
    Qt Code:
    1. #include "ftp3.h"
    2. #include <QFtp>
    3. #include <QMessageBox>
    4.  
    5. ftp3::ftp3(QWidget *parent, Qt::WFlags flags)
    6. : QMainWindow(parent, flags)
    7. {
    8. ui.setupUi(this);
    9. ftp = 0;
    10. file = 0;
    11.  
    12. if (ftp)
    13. {
    14. ftp->abort();
    15. ftp->deleteLater();
    16. ftp = 0;
    17. return;
    18. }
    19.  
    20. ftp = new QFtp;
    21. connect(ftp, SIGNAL(commandFinished(int, bool)),
    22. this, SLOT(ftpCommandFinished(int, bool)));
    23. connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
    24. this, SLOT(ftpListInfo(const QUrlInfo &)));
    25. connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
    26. this, SLOT(updateDataTransferProgress(qint64, qint64)));
    27.  
    28. ftp->connectToHost("ftp.trolltech.com");
    29. ftp->login();
    30. ftp->list();
    31. }
    32.  
    33. ftp3::~ftp3()
    34. {
    35. }
    36.  
    37. void ftp3::ftpCommandFinished(int, bool error)
    38. {
    39.  
    40. if (ftp->currentCommand() == QFtp::ConnectToHost) {
    41. if (error) {
    42. QMessageBox::information(0, tr("FTP"),
    43. tr("Unable to connect to the FTP server "
    44. "at %1. Please check that the host "
    45. "name is correct.")
    46. .arg("192.168.1.3"));
    47. return;
    48. }
    49. return;
    50. }
    51.  
    52. if (ftp->currentCommand() == QFtp::Get)
    53. {
    54. }
    55. if (ftp->currentCommand() == QFtp::List)
    56. {
    57. QMessageBox::information(0, tr("FTP"),"LIST");
    58. }
    59. if (ftp->currentCommand() == QFtp::Put)
    60. {
    61. }
    62. }
    63. void ftp3::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
    64. {
    65. }
    66.  
    67.  
    68. void ftp3::ftpListInfo(const QUrlInfo &urlInfo)
    69. {
    70. fileList<<urlInfo.name() ;
    71. }
    To copy to clipboard, switch view to plain text mode 

    The only difference is that I didn't use the button. I create the ftp client in the constructor of the main window.

    Could you test this? Do you get the same result?

    regards

  10. #10
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    there are still problem! I used qt422 open source and vc2003.I found when i compiled its example in ..\examples\network\ftp in vc enviroment, not used qmake, the exe cannot emit the signal and not even to connect to ftp server. but when used qmake ,all is right. why??

  11. #11
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Can anybody send me a project about qftp demo in vc ?thanks. my email is cxl2253@gmail.com

  12. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Try this one... It's the example I attached. It worked with 4.2.2 and VS 2003.

    Regards
    Attached Files Attached Files

  13. #13
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    Hey, are you sure you don't have a firewall on or anything else that could block the ftp client? Or have you waited enough? Last time I tested the requestFinished response came a little late ( about 10 seconds )?

    Regards

  14. #14
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    thanks,I will test your provided demo. I used the exe compiled by vc and the other compiled by qmake. The first one cannot response, the other can .

  15. #15
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    your code can work well, thanks , but i am surprised that why my code from the QT demo cannot emit the signal? can you help me ? All the code is from QT demo ,I only created a vc project files.
    attached file :
    ftp.zip
    Last edited by cxl2253; 22nd April 2007 at 14:30.

  16. #16
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: why the qftp failed in qmainwindow?where is its signal?

    marcel,I have made a lower mistake, I used the QtNetwork4.lib, not the QtNetworkd4.lib in debug mode .Thaks for your help again.

Similar Threads

  1. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 14:15
  2. Replies: 2
    Last Post: 17th May 2006, 22:01
  3. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 16:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.