Results 1 to 4 of 4

Thread: Problem with QFtp

  1. #1
    Join Date
    Mar 2015
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with QFtp

    I want to use QFtp (I know, its deprecated, but I like it, because it's simple) within a console application (that means no GUI).
    In order to have an event handler, I create a QCoreApplication (see below).
    More or less, this approch is according to what I found in the web.

    Whatever I do, the slot "commandStarted" is never executed, although the Ftp has pending commands.

    I have no idea...

    I would appreciate any help or hint !!!

    Many thanks,
    Michael

    This is my Code:



    Qt Code:
    1. ...
    2.  
    3. /*************************************************************/
    4. /* FTP CLASS */
    5. /*************************************************************/
    6. class Ftp : public QFtp
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Ftp(QObject* parent = 0)
    12. {
    13. connect(this, SIGNAL(done(bool)), QCoreApplication::instance(), SLOT(quit()));
    14. connect(this, SIGNAL(commandStarted(int)), this, SLOT(commandStarted_callback()));
    15. }
    16.  
    17. public slots:
    18. void commandStarted_callback(void);
    19. void start();
    20.  
    21. private:
    22. QFile * _file;
    23. };
    24.  
    25.  
    26.  
    27. int start_ftp_thread()
    28. {
    29.  
    30. int argc = 0;
    31. QCoreApplication app(argc, NULL);
    32.  
    33. /* create new ftp handler */
    34. moc::Ftp* ftp = new moc::Ftp();
    35. ftp->start();
    36.  
    37. /* start handler */
    38. app.exec();
    39.  
    40. return 0;
    41. }
    42.  
    43. /*************************************************************/
    44. /* Entry point of FTP handling */
    45. /*************************************************************/
    46. void moc::Ftp::start()
    47. {
    48. int x;
    49.  
    50. _file = new QFile( "D:\\junk\\qt.txt" );
    51. _file->open(QIODevice::ReadWrite);
    52.  
    53. x = setTransferMode(QFtp::Active);
    54. x = connectToHost("10.9.16.159");
    55. x = login("anonymous");
    56. x = list();
    57. x = get("SCHEDULE.CSV",_file);
    58. x = close();
    59.  
    60. if (hasPendingCommands())
    61. {
    62. std::cout << "I have commands to execute..." << std::endl;
    63. }
    64. }
    65.  
    66. int start_ftp_thread()
    67. {
    68.  
    69. int argc = 0;
    70. QCoreApplication app(argc, NULL);
    71.  
    72. /* create new ftp handler */
    73. moc::Ftp* ftp = new moc::Ftp();
    74. ftp->start();
    75.  
    76. /* start handler */
    77. app.exec();
    78.  
    79. return 0;
    80. }
    81.  
    82.  
    83. /*************************************************************/
    84. /* Called upon command started */
    85. /*************************************************************/
    86. void moc::Ftp::commandStarted_callback(void)
    87. {
    88. std::cout << "Command started..." << std::endl;
    89. }
    90.  
    91.  
    92. int main(void)
    93. {
    94. start_ftp();
    95. return 0;
    96. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by schnudl; 25th March 2015 at 15:48. Reason: quote -> code

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QFtp

    Check the return values of the connect() statement and also check if you see a warning during runtime about connect failing.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2015
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFtp

    Hello !

    Return value is a positive number, referring to a command id.
    Actually, x is 1, 2, 3, ....

    No errors or warnings are emmited.

    Regards, Michael

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QFtp

    Quote Originally Posted by schnudl View Post
    Return value is a positive number, referring to a command id.
    connect() returns a bool

    Quote Originally Posted by schnudl View Post
    No errors or warnings are emmited.
    Since you are on Windows (according to your profile), do you have
    Qt Code:
    1. CONFIG += console
    To copy to clipboard, switch view to plain text mode 
    in your .pro file?

    Is the declaration of your Ftp class in a header or in a source file? If in a header, is it listes in HEADERS in your .pro?

    Cheers,
    _

Similar Threads

  1. QFTP connection problem
    By c3po4 in forum Qt Programming
    Replies: 0
    Last Post: 12th January 2011, 20:54
  2. QFtp weird problem on windows
    By vcp in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2009, 15:13
  3. problem with mkdir() in QFtp
    By fatima in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2009, 23:35
  4. Problem with the put() function of QFtp class
    By whyisosad in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2009, 10:03
  5. Replies: 0
    Last Post: 23rd September 2007, 11:54

Tags for this Thread

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.