PDA

View Full Version : Signals and slots



sylvarant
11th September 2007, 14:58
I just don't seem to get this signal and slot thing, I'm trying to have a funtion executed when Qpushbutton is pressed but I can't get it to work correctly :

i have a public slot
void selectb1();
and a signal
goselect();

now I've connected those 2
connect(this,SIGNAL(goselect()),SLOT(select()));

and then I do
connect(&button1,SIGNAL(clicked()),SLOT(select());

but when I click on the button select ain't called

marcel
11th September 2007, 15:09
Do you have the Q_OBJECT macro in your class declaration?

BTW:


connect(&button1,SIGNAL(clicked()),SLOT(select());

Since button1 is allocated on the stack, it will get destroyed when that function exits. You should create it on the heap.
Your code works only if button1 is a member of that class.

Regards

wysota
11th September 2007, 15:09
Where and how did you declare the signal "goselect()"? And where do you emit it?

sylvarant
11th September 2007, 15:28
It's emited at the end of select and defined in the class defention in the header file

wysota
11th September 2007, 15:48
If it's emitted within select, then unless you call select manually, it won't be emitted. And it all seems weird as you'd create an infinite loop. Can we see the exact code? Both declarations and definitions of the class and especially the places where the concerned signal and slot are used.