PDA

View Full Version : Why do i need to declare a function as a slot?



cbarmpar
29th August 2008, 15:44
Hello all,

I am new to c++, Linux and and qt!

What I don't understand is why I need to declare a function as a public slot in order to connect it with a signal.

Is it possible to connect a public function (not declared as a slot) with a signal?.

Does that means that if I want to connect a function with a signal I have to declare it as a slot before?

How can i connect more than one function with a signal. (for example if condition a exist execute the first function otherwise execute the second)?

Finally: All the tutorials i have been through were using the code generation technique for the GUI. If i use the designer i only need to bother about the connection right?

Many thanks in advance,

Christos

jacek
29th August 2008, 15:51
What I don't understand is why I need to declare a function as a public slot in order to connect it with a signal.
You have to do that, so that moc will know for which methods it should generate meta-data. Take a look at the files generated by moc.


Is it possible to connect a public function (not declared as a slot) with a signal?.
No.


Does that means that if I want to connect a function with a signal I have to declare it as a slot before?
Yes.


How can i connect more than one function with a signal. (for example if condition a exist execute the first function otherwise execute the second)?
If you want to route signals depending on the values of their parameters, you have to do so in your code.


All the tutorials i have been through were using the code generation technique for the GUI. If i use the designer i only need to bother about the connection right?
No, you need a widget subclass which will use the code generated from the .ui file.

See http://doc.trolltech.com/4.4/designer-using-a-component.html

cbarmpar
31st August 2008, 20:38
Many thanks friend that was a clear answer.

Regards