[Development] Should QObject::event() be protected or public?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Mon Mar 18 14:00:06 CET 2024


On 18/03/2024 13:34, André Somers wrote:
> While I know it's easy to work around, I sometimes find myself doing it
> anyway. To me, it signals what API is intended to be used in what way.
> That a class overrides `event`  (or any other public virtual method)
> does not mean that that method is then intended to be called by a user
> of the class as the type you defined. That you overwrote it may just be
> an implementation detail. I think the methods you expose as "public" on
> an API are quite important*. They signal how the user is supposed to use
> an instance of your class. If you have methods in there that are just
> implementation details, then those don't fit. These methods are meant to
> be called by parts of the system that don't see your type as the actual
> type, but as something more basic: a QObject in this case.

But I agree 100% here; this is typically realized in C++ by having the 
entry point public and non-virtual, and have that dispatch to a 
protected virtual. The whole problem we're discussing is that `event()` 
has been made public in the base class and that means it's now public 
API of any QObject subclass, whether they like it or not. :-(

-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - Trusted Software Excellence

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4244 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20240318/b85f46fa/attachment.bin>


More information about the Development mailing list