[Interest] Can slot be virtual?
André Somers
andre at familiesomers.nl
Mon Dec 29 08:27:55 CET 2014
Igor Mironchik schreef op 29-12-2014 om 06:51:
> Slots in Qt can be virtual. But may be there some underwater stones?
>
> What do you know/think?
>
No, this works just fine and can be very useful.
You should, however, not mark the function as a slot more than once.
Mark it as a slot in your base class, then simply override in your
subclasses without adding the slot marker for moc.
One consideration may be API design though. I generally try to keep my
API for _using_ a class separate from the one for _extending_ it. SLOTS
are often (though not always) in the public API surface. Are you sure
that that is also the surface you want to extend? You may consider to
instead have a non-virtual public slot start(), than in turn calls a
virtual private or protected method run(). The start method is then part
of your _use_ API surface, while the _run_ method is part of the
_extention_ API.
André
More information about the Interest
mailing list