PDA

View Full Version : QFtp: connectToHost() fails after using abort()



codeslicer
4th June 2009, 00:42
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:

connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int)));

and

void FTP::showNewState(int state) {
qDebug() << "new State: " << state;
}

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? :confused:

Thanks,
codeslicer

codeslicer
4th June 2009, 12:38
Hmm... there should be a BUMP function.

~codeslicer

codeslicer
4th June 2009, 20:59
Any piece of advice would be helpful. :)

Thanks in advance,
codeslicer

miwarre
17th July 2009, 21:34
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

wysota
17th July 2009, 21:42
abort() is for something else, it sends the ABORT command to an already connected ftp server.

miwarre
18th July 2009, 12:42
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

Krzysztow
12th September 2010, 02:39
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 (http://www.qtcentre.org/threads/33591-QFtp-Connexion-to-false-IP-doesn-t-expirate?p=157737#post157737), hopefully correct one) was connected to the slot, which invoked:


ftp->abort();
ftp->close();
ftp->deleteLater();
ftp->new QFtp();


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.