Fix crash on startup when running screenreader

For exaple Qt Creator would crash when started and a screen reader (eg
NVDA) is running. This is due to updateAccessibility being called during
the ctor of the TextEdit and on Windows the AT can access properties in
the same call resulting in accessing the text control before it's fully
constructed.

Also make sure to not send accessibility updates for non-widget type edits
since we don't support any accessibility in Qt Quick 1.

Backported from Qt 5.3.1 since it also crashes Qt Creator on startup on
Mac (as soon as accessibility is enabled which may be for various
reasons, and basically any app that uses a QTextEdit).

Task-number: QTBUG-38659
Task-number: QTBUG-38738
Change-Id: I6e5c0dc47bd75e63fe013a9edadbabccd52c20ee
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
Frederik Gladhorn 2014-04-29 16:45:33 +02:00 committed by The Qt Project
parent 775f1f777b
commit 667f2449a3

View File

@ -438,7 +438,6 @@ void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString
QObject::connect(doc, SIGNAL(contentsChanged()), q, SLOT(_q_updateCurrentCharFormatAndSelection())); QObject::connect(doc, SIGNAL(contentsChanged()), q, SLOT(_q_updateCurrentCharFormatAndSelection()));
QObject::connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), q, SLOT(_q_emitCursorPosChanged(QTextCursor))); QObject::connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), q, SLOT(_q_emitCursorPosChanged(QTextCursor)));
QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q, SLOT(_q_contentsChanged(int,int,int)));
QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged())); QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged()));
// convenience signal forwards // convenience signal forwards
@ -501,6 +500,8 @@ void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString
q->ensureCursorVisible(); q->ensureCursorVisible();
emit q->cursorPositionChanged(); emit q->cursorPositionChanged();
QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q, SLOT(_q_contentsChanged(int,int,int)), Qt::UniqueConnection);
} }
void QWidgetTextControlPrivate::startDrag() void QWidgetTextControlPrivate::startDrag()
@ -646,7 +647,8 @@ void QWidgetTextControlPrivate::_q_contentsChanged(int from, int charsRemoved, i
{ {
Q_Q(QWidgetTextControl); Q_Q(QWidgetTextControl);
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
if (QAccessible::isActive()) {
if (QAccessible::isActive() && q->parent() && q->parent()->isWidgetType()) {
QTextCursor tmp(doc); QTextCursor tmp(doc);
tmp.setPosition(from); tmp.setPosition(from);
tmp.setPosition(from + charsAdded, QTextCursor::KeepAnchor); tmp.setPosition(from + charsAdded, QTextCursor::KeepAnchor);