From 28651cfc0ce2954c0b6c0e5d3587e4d8b001c1de Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Fri, 2 Jul 2010 16:16:59 +0200 Subject: Fix crash when handleCommand() called before softkeys are updated Softkeys are updated via a compressable event that is posted via the event loop. Since these events are not delivered immediately, there is a chance that a call to handleCommand() could happen before the softkeys have been updated which can lead to a crash if the previous QAction's have been deleted already since the data structure used by QSoftKeyManager is outdated. The likeliness of this is increased by the fact that S60 commands are normally sent from the WSERV active object which has a higher priority than the active object used by Qt's event loop which means commands will preempt the event loop. The fix is to introduce a flag that keeps track of pending update requests and if a command is received while there are outstanding requests, force the softkeys to be updated before handling the command. Task-number: QT-3571 Reviewed-by: axis --- src/gui/kernel/qsoftkeymanager.cpp | 5 +++++ src/gui/kernel/qsoftkeymanager_common_p.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 04e4685..54e6317 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -162,6 +162,7 @@ void QSoftKeyManager::sendKeyEvent() void QSoftKeyManager::updateSoftKeys() { + QSoftKeyManager::instance()->d_func()->pendingUpdate = true; QEvent *event = new QEvent(QEvent::UpdateSoftKeys); QApplication::postEvent(QSoftKeyManager::instance(), event); } @@ -250,6 +251,7 @@ bool QSoftKeyManager::handleUpdateSoftKeys() } d->updateSoftKeys_sys(); + d->pendingUpdate = false; return true; } @@ -275,6 +277,9 @@ bool QSoftKeyManager::event(QEvent *e) #ifdef Q_WS_S60 bool QSoftKeyManager::handleCommand(int command) { + if (QSoftKeyManager::instance()->d_func()->pendingUpdate) + (void)QSoftKeyManager::instance()->handleUpdateSoftKeys(); + return static_cast(QSoftKeyManager::instance()->d_func())->handleCommand(command); } #endif diff --git a/src/gui/kernel/qsoftkeymanager_common_p.h b/src/gui/kernel/qsoftkeymanager_common_p.h index 04ddf7d..1b364d4 100644 --- a/src/gui/kernel/qsoftkeymanager_common_p.h +++ b/src/gui/kernel/qsoftkeymanager_common_p.h @@ -71,7 +71,7 @@ protected: QHash keyedActions; QMultiHash requestedSoftKeyActions; QWidget *initialSoftKeySource; - + bool pendingUpdate; }; QT_END_NAMESPACE -- cgit v0.12