Results 1 to 4 of 4

Thread: Signal and Slot connection not working !!

  1. #1
    Join Date
    May 2010
    Posts
    4
    Platforms
    Windows Symbian S60

    Default Signal and Slot connection not working !!

    Dear All,
    I am pretty new to Qt and I accept this could well be a dumb question.

    I dont understand why the slot connection is not working here !!

    I have a simple form, with a button, and a tree widget. I have created a custom class for the tree widget, as in here and promoted it in the Qt designer !!

    Qt Code:
    1. class QFileBrowser : public QTreeWidget
    2. {
    3. ..
    4. public slots:
    5. void onFilesFoldersSelected();
    6. };
    To copy to clipboard, switch view to plain text mode 

    The main window has a signal defined as follows !!
    Qt Code:
    1. signals:
    2. void filesFoldersSelected();
    To copy to clipboard, switch view to plain text mode 

    the signals and slot are connected as here !!
    Qt Code:
    1. QObject::connect(this, SIGNAL(filesFoldersSelected()), ui->twFileBrowser, SLOT(onFilesFoldersSelected()));
    To copy to clipboard, switch view to plain text mode 

    But i see that i never land in the slot function. I have debugged and at the emitting part of the signal, it is assumed that nothing is connected.
    Qt Code:
    1. if (!sender->d_func()->isSignalConnected(signal_index))
    2. return; // nothing connected to these signals, and no spy .... returns here !! slot is not called !!
    To copy to clipboard, switch view to plain text mode 

    Could anyone please explain what I am doing wrong ??

    Thanks for your time,
    Prakash

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Signal and Slot connection not working !!

    are you sure you are emitting the signal?
    Also, look at the debug output, if there is a problem with the signal slot connection a warning will be plotted to std output.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Signal and Slot connection not working !!

    ...and did you use the Q_OBJECT macro?

    P.s.:
    Quote Originally Posted by prakash437 View Post
    I am pretty new to Qt and I accept this could well be a dumb question.
    therefore we have Newbie section where we also help

  4. #4
    Join Date
    May 2010
    Posts
    4
    Platforms
    Windows Symbian S60

    Default Re: Signal and Slot connection not working !!

    Thank you guys for your answers !! I'm at work and I don't have the source code right now .. So I cannot confirm .. But i am sure, I missed out the Q_OBJECT macro definition !!!

    Thanks again

Similar Threads

  1. Signal and slot connection graph
    By fahlen in forum General Discussion
    Replies: 4
    Last Post: 27th November 2007, 13:47
  2. Passing a pointer in Signal/Slot Connection
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 6th November 2007, 19:04
  3. Replies: 1
    Last Post: 4th November 2006, 06:53
  4. signal slot connection
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 4th July 2006, 13:31
  5. queued signal/slot connection with QList<int>
    By smalls in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 14:32

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.