Qt signals and slots: permissions
There are discrepancies between respected answers here on SO and the
actual Qt docs.
I've read this question and I want some further clarification. Can anyone
confirm:
A signal is always protected, therefore it can be emitted only by the
class or any of its subclasses. I'm not sure this is true; the question
above shows answers supporting this statement. But the Qt docs say:
Signals are public access functions and can be emitted from anywhere, but
we recommend to only emit them from the class that defines the signal and
its subclasses. So which is it?
The words public, private, protected have no use with working with the
signal keyword
The emitted signal is always available to all other classes, that is, any
other class may always connect to that signal (but not emit it).
Despite that all signals are viewable to by all classes, you could still
have two classes with signals of the same name since the connect function
takes the class name as a signal prefix (i.e. SomeClass::itsSignal)
Slots are just functions, and thus may be public, private or protected.
Obviously an outside class will have the ability to control if your class
connects one of its own signals to one of its own slots if the slot is
public. However, again the SO information differs from the docs, which
say: 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. This
means that private is not honored by the signal/slot mechanism?
No comments:
Post a Comment