Results 1 to 11 of 11

Thread: Timing out a QFtp ConnectToHost

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

    Unhappy Timing out a QFtp ConnectToHost

    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

  2. #2
    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: Timing out a QFtp ConnectToHost

    Does the slot get executed?

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

    Default Re: Timing out a QFtp ConnectToHost

    Quote Originally Posted by wysota View Post
    Does the slot get executed?
    No, thats why I am assuming something is wrong.

  4. #4
    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: Timing out a QFtp ConnectToHost

    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.

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

    Unhappy Re: Timing out a QFtp ConnectToHost

    Quote Originally Posted by wysota View Post
    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

  6. #6
    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: Timing out a QFtp ConnectToHost

    What is the exact message you get? Could you also show us the header of the class containing the slot?

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

    Default Re: Timing out a QFtp ConnectToHost

    Quote Originally Posted by wysota View Post
    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 ?

  8. #8
    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: Timing out a QFtp ConnectToHost

    The whole class header, please. Does it contain the Q_OBJECT macro?

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

    Default Re: Timing out a QFtp ConnectToHost

    Quote Originally Posted by wysota View Post
    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);
    };

  10. #10
    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: Timing out a QFtp ConnectToHost

    Did you rerun qmake and make sure the moc_xxx.cpp file got updated?

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

    Smile Re: Timing out a QFtp ConnectToHost

    Quote Originally Posted by wysota View Post
    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

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.