tags:

views:

65

answers:

2

hello, can somebody please explain why do I create in qt public slots but not public signals, thanks in advance

+4  A: 

Slots are normal functions, and can be public, private or protected.

Signals are always protected when eventually generated by the 'moc' program.

But note this (from some old Qt 4.1 docs):

Since slots are normal member functions, they follow the normal C++ rules when called directly. However, as slots, they can be invoked by any component, regardless of its access level, via a signal-slot connection. This means that a signal emitted from an instance of an arbitrary class can cause a private slot to be invoked in an instance of an unrelated class.

sje397
@sje397: thanks I understood one more small question If I have for example two signals in my class, how qt knows which one might be called? (cause I understood that I don't need to implement signals)
lindows
Signals aren't called, they're 'emitted' using the `emit` keyword. The slots that they are connected to via `QObject::connect` are automatically called when that happens.
sje397
@sje397: ok, in this tutorial `http://doc.trolltech.com/4.3/tutorial-t7.html`, they don't use `emit` keyword but they use `valueChanged` custom signal, I tried to change it to `vChanged` signal and received the same effect, so it is difficult to understand if I for example add one more signal without implementation (cause I understood that implementation are done in meta-object file) will this program work?
lindows
emit is just a normal function call. The "emit" is just eye candy to make it more readable. Qt doesn't need to know which are called at all (might happen in yet unknown subclasses after all), moc just generates the implementation for all of them.
Frank
@lindows: changing the signal to "vChanged" should just work. moc will notice the change and generate the implementation for you. Then change the connects accordingly and it should work.
Frank
+1  A: 

SLOTS are functions which can be public, private or protected.Functions are called from any where i.e with in the class or outside the class.But SIGNALSare like events and it should be emitted within the class or from the inherited class so SIGNALSare always protected.

Shadow