Results 1 to 3 of 3

Thread: Synchronous QFtp?

  1. #1
    Join Date
    Apr 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Synchronous QFtp?

    Hello everybody,

    my application checks at start (actually at the beginning of the MainWindow constructor) whether last run quit cleanly, otherwise asks the user if s/he wants to upload a log file to an ftp server. It does something very simple like this:

    Qt Code:
    1. if ( crashed == true )
    2. uploadLogs( );
    To copy to clipboard, switch view to plain text mode 

    where the function uploadLogs( ) takes care of uploading the log file using QFtp. Since QFtp works asynchronously, uploadLogs( ) returns immediately, while the whole ftp login, transfer and closing takes a few seconds. My question is whether is it possible to prevent uploadLogs( ) from returning until the last pending command has completed.

    Thanks a lot for any help.
    Aaron

  2. #2
    Join Date
    Apr 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Synchronous QFtp?

    Hi guys,

    I found the answer. Here if somebody needs it as well:

    Qt Code:
    1. (...)
    2. QUrl url( "ftp://example.com" );
    3. ftp->connectToHost( url.host( ), url.port( 21 ) );
    4. ftp->login( "anonymous", "" );
    5.  
    6. // Put all the ftp commands you need
    7.  
    8. ftp->close( );
    9.  
    10. // Process the queue of ftp events
    11. while ( ( ftp->hasPendingCommands( ) ) || ( ftp->currentCommand( ) != QFtp::None ) )
    12. qApp->processEvents( );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Synchronous QFtp?

    Your code will use 100% CPU.
    A better solution is to use a QEventLoop and connect the QFtp done() signal to the quit() of the QEventLoop. Then you can just start the QFtp and then run eventLoop.exec().
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

Similar Threads

  1. QFtp and non-Latin1 FTP servers
    By miwarre in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2009, 13:44
  2. Synchronizing QFtp
    By arun_vj in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 13:31
  3. QFtp Trouble !
    By Fastman in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 13:08
  4. why the qftp failed in qmainwindow?where is its signal?
    By cxl2253 in forum Qt Programming
    Replies: 15
    Last Post: 22nd April 2007, 14:51
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 19:10

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.