Results 1 to 7 of 7

Thread: QFtp: connectToHost() fails after using abort()

  1. #1
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry QFtp: connectToHost() fails after using abort()

    Hi,

    In my program, I have a timed function that, after 10 seconds, aborts a connection. Usually this function isn't used, but in order to test it, I changed the port of an FTP host from 21 to 20. This causes QFtp::connectToHost() to run indefinitely. In order to test for any state changes I used:
    Qt Code:
    1. connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int)));
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. void FTP::showNewState(int state) {
    2. qDebug() << "new State: " << state;
    3. }
    To copy to clipboard, switch view to plain text mode 

    However, it seems that after connectToHost(server, 20) is started, the state changes to "2" (QFtp::Connecting) and neither close() nor abort() change the state of the QFtp object. Thus, I can't create any new connections.

    Creating new QFtp objects is not available to me because deleting a QFtp object while it's connecting only causes my program to crash.

    Any ideas on what to do?

    Thanks,
    codeslicer

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFtp: connectToHost() fails after using abort()

    Hmm... there should be a BUMP function.

    ~codeslicer

  3. #3
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFtp: connectToHost() fails after using abort()

    Any piece of advice would be helpful.

    Thanks in advance,
    codeslicer

  4. #4
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFtp: connectToHost() fails after using abort()

    Hi,

    I have the same problem and so far I did not find a solution. Any help would be appreciated by me too!

    Thanks!

    Miwarre

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp: connectToHost() fails after using abort()

    abort() is for something else, it sends the ABORT command to an already connected ftp server.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFtp: connectToHost() fails after using abort()

    Thanks wysota.

    This leaves open the initial issue: how do you cancel/interrupt/terminate/kill/... connectToHost() ?

    This is even more needed as connectToHost() in many cases does not seem to time-out at all...

    Miwarre

    P.S.: what you say matches what is actually happening, but it was not evident from the documentation, which seems to state that abort() can abort any command, in some cases by also sending ABORT to the server:
    Aborts the current command and deletes all scheduled commands.

    If there is an unfinished command [...], this function sends an ABORT command to the server. [...]

    For all other commands that are affected by the abort(), no signals are emitted.
    Thanks again, miwarre

  7. #7
    Join Date
    Jul 2009
    Posts
    26
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows

    Default Re: QFtp: connectToHost() fails after using abort()

    Quote Originally Posted by miwarre View Post
    Thanks wysota.

    This leaves open the initial issue: how do you cancel/interrupt/terminate/kill/... connectToHost() ?

    This is even more needed as connectToHost() in many cases does not seem to time-out at all...

    Miwarre

    P.S.: what you say matches what is actually happening, but it was not evident from the documentation, which seems to state that abort() can abort any command, in some cases by also sending ABORT to the server:

    Thanks again, miwarre
    Hi, if You still dwell on that or someone else is looking for information on this problem. Probably, Your application crashes, because You use delete operator on the QFtp instance. In this case, if there was something posted, sent to this object, or signal invoked, there is possibility, it will crash. Instead, try using QObject::deleteLater(), which causes that instance is deleted just at the end of the QEventLoop.

    It worked in my case. I worked with ftp server that run on the machine which could get disconnected and, what is worse, restared after being disconnected. Thus, I still had connection opened, and couldn't work on the QFtp instance any more. The timeout signal (see class FtpWatcher in this thread, hopefully correct one) was connected to the slot, which invoked:
    Qt Code:
    1. ftp->abort();
    2. ftp->close();
    3. ftp->deleteLater();
    4. ftp->new QFtp();
    To copy to clipboard, switch view to plain text mode 

    Probably it wasn't necessary to call first two functions, but I tried to be safe (If by miracle connection got back - but probably then, I wouldn't manage to wait for it to be closed before destruction). Hopefully it helps somenone.

    All the best,
    Chris.

Similar Threads

  1. Replies: 2
    Last Post: 17th April 2009, 23:36
  2. Timing out a QFtp ConnectToHost
    By skp in forum Qt Programming
    Replies: 10
    Last Post: 27th April 2008, 14: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.