summaryrefslogtreecommitdiffstats
path: root/src/gui/accessible/qaccessiblecache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/accessible/qaccessiblecache.cpp')
-rw-r--r--src/gui/accessible/qaccessiblecache.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/gui/accessible/qaccessiblecache.cpp b/src/gui/accessible/qaccessiblecache.cpp
index a8255e04c02..b5dcdca6270 100644
--- a/src/gui/accessible/qaccessiblecache.cpp
+++ b/src/gui/accessible/qaccessiblecache.cpp
@@ -4,6 +4,7 @@
#include "qaccessiblecache_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qloggingcategory.h>
+#include <private/qguiapplication_p.h>
#if QT_CONFIG(accessibility)
@@ -18,6 +19,7 @@ Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCache, "qt.accessibility.cache");
*/
static QAccessibleCache *accessibleCache = nullptr;
+static bool inCacheDestructor = false;
static void cleanupAccessibleCache()
{
@@ -31,6 +33,8 @@ QAccessibleObjectDestroyedEvent::~QAccessibleObjectDestroyedEvent()
QAccessibleCache::~QAccessibleCache()
{
+ inCacheDestructor = true;
+
for (QAccessible::Id id: idToInterface.keys())
deleteInterface(id);
}
@@ -176,10 +180,27 @@ void QAccessibleCache::sendObjectDestroyedEvent(QObject *obj)
void QAccessibleCache::deleteInterface(QAccessible::Id id, QObject *obj)
{
- QAccessibleInterface *iface = idToInterface.take(id);
+ const auto it = idToInterface.find(id);
+ if (it == idToInterface.end()) // the interface may be deleted already
+ return;
+
+ QAccessibleInterface *iface = *it;
qCDebug(lcAccessibilityCache) << "delete - id:" << id << " iface:" << iface;
- if (!iface) // the interface may be deleted already
+ if (!iface) {
+ idToInterface.erase(it);
return;
+ }
+
+ // QObjects send this from their destructors, but the interfaces
+ // with no associated object call deleteInterface directly.
+ if (!inCacheDestructor && !obj && !iface->object()) {
+ if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive()) {
+ QAccessibleObjectDestroyedEvent event(id);
+ QAccessible::updateAccessibility(&event);
+ }
+ }
+
+ idToInterface.erase(it);
interfaceToId.take(iface);
if (!obj)
obj = iface->object();