@user2448027 answer is correct, but there is a missing point in Qt's design pattern: different applications of private slots
vs public slots
.
By making slot private
you force users of the object to use connect
function to call the slot, rather than member access operators(.
or ->
).
Imagine you have a slow or blocking code in one of the slots of your class. You expect users of the class to move the created object to another thread, so the owner of this object (GUI or some object's related to GUI) would not freeze or block by calling this slot. Here is the point: if the slot is called directly by .
or ->
operators, it will block. Because the current thread of caller method uses the slot, it can only happen if you use public slot. The solution is to make the slot private
, so the user could only call it with connect
, but not member access operators(.
or ->
).
Conclusion:
- If you have blocking slots, make them
private
.
- If the slots are used as simple settings of object property, make them
public
.
- If you need some methods with return values or inconstant reference arguments, do not even make them slots (it is nonsense), only
public
is enough.