Details
-
Bug
-
Resolution: Cannot Reproduce
-
P4: Low
-
None
-
5.5.1
-
None
-
OS X, Windows
Description
Sometimes (for example pasting in an empty QTextEdit) wrong parameter values are passed when QTextDocument::contentsChange() signal is emitted.
#include <QtWidgets/QApplication> #include <QtWidgets/QTextEdit> QSharedPointer<QTextEdit> field; void onContentsChange(int position, int removed, int added) { Q_UNUSED(removed); QTextCursor c(field->document()->docHandle(), 0); c.movePosition(QTextCursor::End); Q_ASSERT(position + added <= c.position()); } int main(int argc, char *argv[]) { QApplication a(argc, argv); field.reset(new QTextEdit()); QObject::connect(field->document(), &QTextDocument::contentsChange, onContentsChange); field->setGeometry(100, 100, 150, 30); field->show(); return a.exec(); }
In this example if we edit text in normal ways (print and remove characters) or paste text in the end of some not empty text inserted everything is going fine. But if we paste text in an empty field the assert triggers: we get "removed=1" (instead of 0) and "added" is larger by 1 than it should be.
In more complicated situations (pasting instead of part of selected text) we are unable to determine the correct changed part of the QTextEdit content.
Example project (Xcode 7) is attached.
Attachments
Issue Links
- is duplicated by
-
QTBUG-82455 QTextDocument::contentsChange(int,int,int) values are incompatible with QTextCursor
- Closed