xcb: Initialize accessibility lazily, since it requires an event-dispatcher

QSpiAccessibleBridge uses a D-BUS connection, which in turn uses socket
notifiers and timers internally. Neither of these can be used before
a event-dispatcher is in place, so we need to defer creation of the
accessibility interface until later. We assume that clients will
only call QXcbIntegration::accessibility() when an event-dispatcher
is set up, but to be extra safe we do an assert, so that failures of
this pre-condition will trigger at the place they are caused -- not
as failures to register socket notifiers and timers in the D-BUS code.

Change-Id: I4f9d8362a3f285c3da9045d1ff6b8e7b04570488
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
Tor Arne Vestbø 2013-10-01 13:45:35 +02:00 committed by The Qt Project
parent 4e20df5fc5
commit 3bcc44268e
2 changed files with 9 additions and 4 deletions

View File

@ -173,9 +173,6 @@ QXcbIntegration::QXcbIntegration(const QStringList &parameters, int &argc, char
m_fontDatabase.reset(new QGenericUnixFontDatabase());
m_inputContext.reset(QPlatformInputContextFactory::create());
#if !defined(QT_NO_ACCESSIBILITY) && !defined(QT_NO_ACCESSIBILITY_ATSPI_BRIDGE)
m_accessibility.reset(new QSpiAccessibleBridge());
#endif
}
QXcbIntegration::~QXcbIntegration()
@ -333,6 +330,14 @@ QPlatformInputContext *QXcbIntegration::inputContext() const
#ifndef QT_NO_ACCESSIBILITY
QPlatformAccessibility *QXcbIntegration::accessibility() const
{
#if !defined(QT_NO_ACCESSIBILITY_ATSPI_BRIDGE)
if (!m_accessibility) {
Q_ASSERT_X(QCoreApplication::eventDispatcher(), "QXcbIntegration",
"Initializing accessibility without event-dispatcher!");
m_accessibility.reset(new QSpiAccessibleBridge());
}
#endif
return m_accessibility.data();
}
#endif

View File

@ -114,7 +114,7 @@ private:
QScopedPointer<QPlatformInputContext> m_inputContext;
#ifndef QT_NO_ACCESSIBILITY
QScopedPointer<QPlatformAccessibility> m_accessibility;
mutable QScopedPointer<QPlatformAccessibility> m_accessibility;
#endif
QScopedPointer<QPlatformServices> m_services;