Fix multiple QQuickTextEdit::textChanged emission
Signal disconnection previously failed due to mixing string based connection with function pointer based one causing QQuickTextEdit::textChanged to be emitted multiple times Fixes: QTBUG-130676 Pick-to: 6.8 Change-Id: I3f948aa4b37a9b3a9ddd6240e248fd96fee36175 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
fdc2a052aa
commit
b3e70d1c20
|
@ -268,7 +268,7 @@ void QQuickTextControlPrivate::setContent(Qt::TextFormat format, const QString &
|
||||||
const int oldCursorPos = cursor.position();
|
const int oldCursorPos = cursor.position();
|
||||||
|
|
||||||
// avoid multiple textChanged() signals being emitted
|
// avoid multiple textChanged() signals being emitted
|
||||||
qmlobject_disconnect(doc, QTextDocument, SIGNAL(contentsChanged()), q, QQuickTextControl, SIGNAL(textChanged()));
|
QObject::disconnect(doc, &QTextDocument::contentsChanged, q, &QQuickTextControl::textChanged);
|
||||||
|
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty()) {
|
||||||
// clear 'our' cursor for insertion to prevent
|
// clear 'our' cursor for insertion to prevent
|
||||||
|
@ -308,7 +308,7 @@ void QQuickTextControlPrivate::setContent(Qt::TextFormat format, const QString &
|
||||||
}
|
}
|
||||||
cursor.setCharFormat(charFormatForInsertion);
|
cursor.setCharFormat(charFormatForInsertion);
|
||||||
|
|
||||||
qmlobject_connect(doc, QTextDocument, SIGNAL(contentsChanged()), q, QQuickTextControl, SIGNAL(textChanged()));
|
QObject::connect(doc, &QTextDocument::contentsChanged, q, &QQuickTextControl::textChanged);
|
||||||
emit q->textChanged();
|
emit q->textChanged();
|
||||||
doc->setUndoRedoEnabled(previousUndoRedoState);
|
doc->setUndoRedoEnabled(previousUndoRedoState);
|
||||||
_q_updateCurrentCharFormatAndSelection();
|
_q_updateCurrentCharFormatAndSelection();
|
||||||
|
@ -615,10 +615,10 @@ void QQuickTextControl::setDocument(QTextDocument *doc)
|
||||||
QAbstractTextDocumentLayout *layout = doc->documentLayout();
|
QAbstractTextDocumentLayout *layout = doc->documentLayout();
|
||||||
connect(layout, &QAbstractTextDocumentLayout::update, this, &QQuickTextControl::updateRequest);
|
connect(layout, &QAbstractTextDocumentLayout::update, this, &QQuickTextControl::updateRequest);
|
||||||
connect(layout, &QAbstractTextDocumentLayout::updateBlock, this, &QQuickTextControl::updateRequest);
|
connect(layout, &QAbstractTextDocumentLayout::updateBlock, this, &QQuickTextControl::updateRequest);
|
||||||
connect(doc, &QTextDocument::contentsChanged, this, [d, this]() {
|
connect(doc, &QTextDocument::contentsChanged, this, [d]() {
|
||||||
d->_q_updateCurrentCharFormatAndSelection();
|
d->_q_updateCurrentCharFormatAndSelection();
|
||||||
emit textChanged();
|
|
||||||
});
|
});
|
||||||
|
connect(doc, &QTextDocument::contentsChanged, this, &QQuickTextControl::textChanged);
|
||||||
connect(doc, &QTextDocument::cursorPositionChanged, this, [d](const QTextCursor &cursor) {
|
connect(doc, &QTextDocument::cursorPositionChanged, this, [d](const QTextCursor &cursor) {
|
||||||
d->_q_updateCursorPosChanged(cursor);
|
d->_q_updateCursorPosChanged(cursor);
|
||||||
});
|
});
|
||||||
|
|
|
@ -206,6 +206,7 @@ private slots:
|
||||||
void cursorRectangle_QTBUG_38947();
|
void cursorRectangle_QTBUG_38947();
|
||||||
void textCached_QTBUG_41583();
|
void textCached_QTBUG_41583();
|
||||||
void doubleSelect_QTBUG_38704();
|
void doubleSelect_QTBUG_38704();
|
||||||
|
void textChanged_QTBUG_130676();
|
||||||
|
|
||||||
void padding();
|
void padding();
|
||||||
void paddingAndWrap();
|
void paddingAndWrap();
|
||||||
|
@ -6217,6 +6218,15 @@ void tst_qquicktextedit::doubleSelect_QTBUG_38704()
|
||||||
QCOMPARE(selectionSpy.size(), 3);
|
QCOMPARE(selectionSpy.size(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_qquicktextedit::textChanged_QTBUG_130676()
|
||||||
|
{
|
||||||
|
QQuickTextEdit textEdit;
|
||||||
|
QSignalSpy spy(&textEdit, SIGNAL(textChanged()));
|
||||||
|
QVERIFY(spy.isValid());
|
||||||
|
textEdit.setText("Hello Qt");
|
||||||
|
QVERIFY(spy.count() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_qquicktextedit::padding()
|
void tst_qquicktextedit::padding()
|
||||||
{
|
{
|
||||||
QScopedPointer<QQuickView> window(new QQuickView);
|
QScopedPointer<QQuickView> window(new QQuickView);
|
||||||
|
|
Loading…
Reference in New Issue