Connecting a Button Click signal to member function
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 ...
Code:
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.
Re: Connecting a Button Click signal to member function
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.
Re: Connecting a Button Click signal to member function
if foo() so much valuable that it cant be slot.. then why not use a third func() and call foo() from there.
Re: Connecting a Button Click signal to member function
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.
Re: Connecting a Button Click signal to member function
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.