PDA

View Full Version : Timing out a QFtp ConnectToHost



skp
26th April 2008, 20:19
Hey all,
I am badly stuck with following code not
producing a timeout signal.

If the following code seems to be insufficient,
can somebody please tell me how to timeout a
QFtp connectToHost command after a definite
time. I would really appreciate it.

In Constructor :


timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(testNetwork()));

In the Init function :


ftp->connectToHost("server.com");
timer->setSingleShot(1);
timer->start(2000);

if (1 == loop.exec())
return false;


void testNetwork()
{
ftp->abort();
QMessageBox::information(this, tr("FTP"), tr("Trouble Connecting to the Server. \nPlease try later."))
loop.exit(0);
}

Thank you
skp

wysota
26th April 2008, 22:51
Does the slot get executed?

skp
27th April 2008, 07:46
Does the slot get executed?

No, thats why I am assuming something is wrong.

wysota
27th April 2008, 12:03
Is testNetwork() declared as a slot? Does the class you declare it in contain the Q_OBJECT macro? Please build your application with console support turned on (CONFIG+=console), run the application from command line (or some other way where you have access to the console output) and check whether Qt issues any warning about signal-slot connections.

skp
27th April 2008, 12:23
Is testNetwork() declared as a slot? Does the class you declare it in contain the Q_OBJECT macro? Please build your application with console support turned on (CONFIG+=console), run the application from command line (or some other way where you have access to the console output) and check whether Qt issues any warning about signal-slot connections.

Hey Wysota,
Thanks for that valuable comment, I looked at the command
line output and it says ( as you must have expected )
"No Such Slot className::SLOTname()"

I checked that I have declared it under private slots:

Is there anything else I should make sure ?

thank you
skp

wysota
27th April 2008, 12:24
What is the exact message you get? Could you also show us the header of the class containing the slot?

skp
27th April 2008, 12:30
What is the exact message you get? Could you also show us the header of the class containing the slot?

Following is the code Snippet where the SIGNAL SLOT is connected ::


ftp = new QFtp(this);
connect(ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(ftpCommandFinished(int, bool)));
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(updateProgressBar(qint64, qint64)));

QMessageBox::information(this, tr("FTP"), tr("Trouble Connecting to the Server. \nPlease try later."));
ftp->connectToHost("192.168.36.251");

timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(testNetwork()));
timer->setSingleShot(1);
timer->start(2000);

progressDialog->setLabelText(tr("Connecting to the Host"));
progressDialog->exec();

the exact error Message is ::

QObject::connect: No such slot projectDC::testNetwork()

the header file contains ::


private slots:

void ftpCommandFinished ( int, bool );
void updateProgressBar( qint64, qint64 );
void cancelDownload();

void testNetwork();

Anything else ?

wysota
27th April 2008, 12:35
The whole class header, please. Does it contain the Q_OBJECT macro?

skp
27th April 2008, 12:40
The whole class header, please. Does it contain the Q_OBJECT macro?

Yes it totally does and the two signals above in the code(ftpCommandFinished & updateProgressBar) work very fine without introducing the
QTimer business.


class projectDC : public QDialog
{
Q_OBJECT
public:
QSize sizeHint() const;
projectDC(QWidget *parent = 0);

private slots:

void ftpCommandFinished ( int, bool );
void updateProgressBar( qint64, qint64 );
void cancelDownload();

void testNetwork();
private:
QTimer *timer;
QFtp *ftp;

protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void closeEvent(QCloseEvent *event);
};

wysota
27th April 2008, 13:42
Did you rerun qmake and make sure the moc_xxx.cpp file got updated?

skp
27th April 2008, 14:10
Did you rerun qmake and make sure the moc_xxx.cpp file got updated?

Dude Holy Thanks man !
I deleted all possible moc* ( i kept missing those in release folder I guess not sure + windows sucks)
I can't be more angry/ashamed, Many thanks man ...

skp