[Development] Should QObject::event() be protected or public?
Ilya Fedin
fedin-ilja2010 at ya.ru
Wed Mar 13 09:35:48 CET 2024
On Wed, 13 Mar 2024 07:58:20 +0000
Marc Mutz via Development <development at qt-project.org> wrote:
> Hi,
>
> In API review, we detected some overrides that changed the access
> specifier vis-a-vis the original virtual function
> (https://wiki.qt.io/Things_To_Look_Out_For_In_Reviews#Polymorphic_Classes
> Item 5.3).
>
> One of them was a protected reimplementation of QObject::event()
> (which itself is public).
>
> The reason why QObject::event() is public seems lost to history, but
> the feeling in the review comments¹ was that it should have been
> protected from the get-go (and QObject befriended by whoever delivers
> events).
>
> If you see any reason for QObject::event() to stay public in Qt 7 and
> not become protected, please speak up before we fork Qt 7.0 :)
>
> Thanks,
> Marc
>
> ¹
> https://codereview.qt-project.org/c/qt/qtdeclarative/+/528290/comment/f51938ca_fd065a18/
>
Telegram Desktop has a use-case that it has a menu bar with actions
having shortcuts like QKeySequence::Copy which are implemented as
sending a QKeyEvent press/release sequence with the appropriate (same)
shortcut to the currently focused widget. This is done using
QObject::event directly to avoid a recursion as the menu bar hijacks
the QKeyEvents if QCoreApplication::sendEvent is used.
More information about the Development
mailing list