PDA

View Full Version : Connecting a Button Click signal to member function



URPradhan
27th November 2009, 06:31
As per the Qt docs, We can connect signals to slots in a many-to-many fashion.

But lets say I have a member function void foo() and NOT declared in slots declaration section, and its just a member function. Then Can i connect the buton click SIGNAL to foo() member function ? Like ...


connect(myPushButton, SIGNAL(clicked()),this, SLOT(foo()));


When I've declared void foo() in private slots: section, its getting called properly. But when I'm declaring void foo() in private: section, its not getting called.

So, Is there any way we connect a signal to a member function without declaring it as a slot member function ?

Thank you.

wysota
27th November 2009, 07:41
Methods are declared as slots to be able to be connected to signals. Thus the answer that you can't connect to a method which is not a slot.

nish
27th November 2009, 09:58
if foo() so much valuable that it cant be slot.. then why not use a third func() and call foo() from there.

squidge
27th November 2009, 10:30
Don't forget that you can always call a slot as a normal function call. Defining a function as a slot just registers it in the meta object data so you can connect to it.

URPradhan
27th November 2009, 13:00
Thank you.
I understood what you all said but I was asking to clarify it.
Else there is no harm for me to put foo() (my valuable fn :-) ) in private slots: section.