Results 1 to 7 of 7

Thread: A signal/slot connect isn't working.

  1. #1
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default A signal/slot connect isn't working.

    Hey,
    for a little project of mine, i've build a little dialog.

    Now, when the dialog finishes, the dialog's buttonBox should send out the accept () signal.

    Qt Code:
    1. bool acceptedConnection = connect (
    2. this->dialog, SIGNAL (accepted ()),
    3. this, SLOT (dataFilledIn())
    4. );
    5.  
    6. qDebug ( acceptedConnection?
    7. "acceptedConnection made":
    8. "acceptedConnection FAILED"
    9. );
    10. //connecting rejectedConnection
    11. bool rejectedConnection = connect (
    12. this->dialog->buttonBox, SIGNAL (rejected ()),
    13. qApp, SLOT (closeAllWindows())
    14. );
    15.  
    16. qDebug ( rejectedConnection?
    17. "rejectedConnection made":
    18. "rejectedConnection FAILED"
    19. );
    To copy to clipboard, switch view to plain text mode 
    As you can see, i'm connecting everything in exacly the same way. But for some reason,
    dataFilledIn () never gets called. The debugger tells me nothing about this; connect returns true.

    The following is the header file. I hope you can find something that i've missed.

    thanks in advance!
    Qt Code:
    1. #ifndef DATADOWNLOADER_H
    2. #define DATADOWNLOADER_H
    3. #include <QWidget>
    4. class HTTPObject;
    5. class TorpiaAnalyserSettings;
    6. class mainwindow;
    7.  
    8. class DataDownloader : public QWidget {
    9. Q_OBJECT
    10. public:
    11. DataDownloader (QWidget *);
    12. public slots:
    13. void dataFilledIn ();
    14.  
    15. void usernameUpdated (QString );
    16. void passwordUpdated (QString );
    17. void intervalUpdated (int);
    18. void maxRequestUpdated (int);
    19. void rankStartUpdated (int);
    20. void rankEndUpdated (int);
    21.  
    22. void useDownload (int);
    23.  
    24. private:
    25. HTTPObject * downloader;
    26. TorpiaAnalyserSettings * dialog;
    27. mainwindow * window;
    28.  
    29. void connectSignals (int);
    30. public: /*properties*/
    31. QString username;
    32. QString password;
    33. int interval;
    34. int maxRequest;
    35. int rankStart;
    36. int rankEnd;
    37.  
    38. };
    39.  
    40. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A signal/slot connect isn't working.

    accepted () is emitted only when u click OK button on the dialog.. r u clickin the OK button only? also, note that the signal wont be emitted when the dialog is hidden or its not visible..make sure all criterias of the signal being emitted are met..otherwise, there is no reason why the slot wont be called

  3. #3
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A signal/slot connect isn't working.

    Quote Originally Posted by talk2amulya View Post
    accepted () is emitted only when u click OK button on the dialog.. r u clickin the OK button only? also, note that the signal wont be emitted when the dialog is hidden or its not visible..make sure all criterias of the signal being emitted are met..otherwise, there is no reason why the slot wont be called
    I am indeed clicking the ok button. As you can see, the program exits when i click the other one.

    Now, i just noticed i didn't gave all information.
    Qt Code:
    1. DataDownloader::DataDownloader (QWidget * parent = 0)
    2. :QWidget (parent)
    3. {
    4. .......
    5.  
    6. this->dialog->show ();
    7.  
    8.  
    9. this->connectSignals (1);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void DataDownloader::dataFilledIn ()
    2. {
    3. qDebug ( "Requesting downloads, showing mainwindow and ignoring the dialog");
    4. this->connectSignals (2);
    5. this->window->show ();
    6. this->dialog->done (1);
    7. ..............
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A signal/slot connect isn't working.

    is this a customized dialog u r using? i ask it cuz of this

    Qt Code:
    1. this->dialog->buttonBox
    To copy to clipboard, switch view to plain text mode 

    normally there is no buttonBox in the QDialog as far as i know

  5. #5
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A signal/slot connect isn't working.

    Oh, sorry.
    The dialog is created through a QT Designer interface, a ui file. Sorry that i didn't mention that :P

    hm. In the designer, i've removed the default signal/slot.

    I think i know the problem, brb , testing it.

    Oke, it was my own fault.

    By removing those connections, i've removed the signal that was sent out.

    fixed! thanks

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A signal/slot connect isn't working.

    i think in one of the connect statements, u have used

    this->dialog

    and other u have used

    this->dialog->buttonBox

    there must be ur issue..signal isnt properly connected..

  7. #7
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A signal/slot connect isn't working.

    Quote Originally Posted by talk2amulya View Post
    i think in one of the connect statements, u have used

    this->dialog

    and other u have used

    this->dialog->buttonBox

    there must be ur issue..signal isnt properly connected..
    and that too, is true

    It would seem that i'm a bit too easy with things. need to pay more attention

Similar Threads

  1. QObject signal/slot not working
    By Msnforum in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 23:50
  2. Connect not working
    By xgoan in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2006, 12:27

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.