Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.5.1
-
None
-
qt5-qtbase-5.5.1-2.fc24.x86_64
Description
Behaviour below is with qt5-qtbase-5.5.1-2.fc24.x86_64 and qt-4.8.7-4.fc24.x86_64, but I think it is safe to assume that any released Qt version is affected.
Consider this test application:
#include <QApplication> #include <QPlainTextEdit> #include <QPushButton> #include <QTextStream> #include <QVBoxLayout> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget* parent = 0) : QWidget(parent) { mTextEdit = new QPlainTextEdit(this); mClearButton = new QPushButton("Clear", this); setLayout(new QVBoxLayout()); layout()->addWidget(mTextEdit); layout()->addWidget(mClearButton); connect(mTextEdit->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(slotContentsChange(int,int,int))); connect(mClearButton, SIGNAL(clicked()), mTextEdit, SLOT(clear())); } private slots: void slotContentsChange(int pos, int removed, int added) { QTextStream(stdout) << "pos: " << pos << ", removed: " << removed << ", added: " << added << endl; } private: QPlainTextEdit* mTextEdit; QPushButton* mClearButton; }; int main(int argc, char* argv[]) { QApplication app(argc, argv); Widget widget; widget.show(); return app.exec(); } #include "moc_test.cpp"
Following actions result in incorrect lengths reported for added and/or removed by QTextDocument::contentsChange:
- Pasting some text into the empty text edit, i.e. "Hi":
pos: 0, removed: 1, added: 3
=> Added and removed are too large by 1
- Pasting some text (again, "Hi") at pos 0 into the text edit (assume it already contains "Hi"):
pos: 0, removed: 3, added: 5
=> Added and removed are too large by 1
- Clearing the text edit (which now contains "HiHi"):
pos: 0, removed: 0, added: 1
pos: 0, removed: 5, added: 0
=> A phantom character is added, and then removed together with the actual "HiHi"
Attachments
Issue Links
- duplicates
-
QTBUG-3495 QTextDocument::contentsChange singal does not gives correct value.
-
- Open
-