Skip to content

Commit

Permalink
QShortcut: call base class implementation in event()
Browse files Browse the repository at this point in the history
QShortcut::event() did not call the base class implementation
QObject::event() which caused that e.g. QEvent::DeferredDelete was not
handled.
Fix it by calling QObject::event() when the event was not handled.

Fixes: QTBUG-66809
Change-Id: Ideebc980bc658f8f2b9ec4417e738bccda5eeab5
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
chehrlic committed Sep 5, 2019
1 parent 15edba4 commit a42a451
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/widgets/kernel/qshortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,24 +665,22 @@ int QShortcut::id() const
bool QShortcut::event(QEvent *e)
{
Q_D(QShortcut);
bool handled = false;
if (d->sc_enabled && e->type() == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){
#if QT_CONFIG(whatsthis)
if (QWhatsThis::inWhatsThisMode()) {
QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis);
handled = true;
} else
#endif
if (se->isAmbiguous())
emit activatedAmbiguously();
else
emit activated();
handled = true;
return true;
}
}
return handled;
return QObject::event(e);
}
#endif // QT_NO_SHORTCUT

Expand Down
10 changes: 10 additions & 0 deletions tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private slots:
void context();
void duplicatedShortcutOverride();
void shortcutToFocusProxy();
void deleteLater();

protected:
static Qt::KeyboardModifiers toButtons( int key );
Expand Down Expand Up @@ -1305,5 +1306,14 @@ void tst_QShortcut::shortcutToFocusProxy()
QCOMPARE(le.text(), QString());
}

void tst_QShortcut::deleteLater()
{
QWidget w;
QPointer<QShortcut> sc(new QShortcut(QKeySequence(Qt::Key_1), &w));
sc->deleteLater();
QTRY_VERIFY(!sc);
}


QTEST_MAIN(tst_QShortcut)
#include "tst_qshortcut.moc"

0 comments on commit a42a451

Please sign in to comment.