Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
4.7.1
-
None
-
debian amd64, qt-4.7.1
-
6ae84f1183e91c910ca92a55e37f8254ace805c0, 34c297faca93e1286573b2a01127e4e7af00aff2
Description
The select() method can fail, it doesnt check for return value of movePosition() calls, which is false on a non-valid cursor
see selectall-fail-demo.7z (it is a modified syntaxhighlighter example, so you may just put it in the qt compile dir instead of the original one)
you will see to textedits.
both of them should select all their contents when you modify it (type a character or delete one)
move the cursor to the end (ctrl+end) and press backspace.
in the second textedit the text will still be selected, while in the left one selection will not happen
***
here is part of mainwindow code which helps to reproduce the bug
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->textEdit, SIGNAL(textChanged()), SLOT(doMagic())); } void MainWindow::doMagic() { // crash on this line ui->textEdit->selectAll(); // clear selection just for convenience of testing QTextCursor cur = ui->textEdit->textCursor(); cur.clearSelection(); ui->textEdit->setTextCursor(cur); }
compile it and try type at least one character and then delete it with backspace.
the actual code where issue was first time noticed
https://github.com/psi-im/psi/blob/master/src/widgets/psitextview.cpp#L131 (getTextHelper method)
why that was at all needed
https://github.com/psi-im/psi/blob/master/src/widgets/psitextview.h#L47 (look at comment)
back trace:
#0 0x00007ffff4feeeec in QTextLayout::lineCount (this=0x0) at text/qtextlayout.cpp:798
No locals.
#1 0x00007ffff504e9e7 in QTextCursorPrivate::blockLayout (this=0x12a4430, block=...) at text/qtextcursor.cpp:854
tl = 0x0
#2 0x00007ffff504c9ed in QTextCursorPrivate::movePosition (this=0x12a4430, op=QTextCursor::Start, mode=QTextCursor::MoveAnchor) at text/qtextcursor.cpp:378
adjustX = true
layout = 0x7fffffffada0
line =
newPosition = 25645152
moved = false
blockIt =
relativePos = 0
#3 0x00007ffff504f213 in QTextCursor::movePosition (this=0x1875060, op=QTextCursor::Start, mode=QTextCursor::MoveAnchor, n=1) at text/qtextcursor.cpp:1225
previousPosition = 7
#4 0x00007ffff5050368 in QTextCursor::select (this=0x1875060, selection=QTextCursor::Document) at text/qtextcursor.cpp:1548
block = {p = 0x1875150, n = 0}
#5 0x00007ffff4fd0334 in QTextControl::selectAll (this=0x1874eb0) at text/qtextcontrol.cpp:874
d = 0x1874fc0
selectionLength = 0
#6 0x00007ffff52a3957 in QTextEdit::selectAll (this=0x129c4b0) at widgets/qtextedit.cpp:1040
d = 0x129cbd0
workaround:
move cursor somewhere before selectAll
its seems the bug was introduced in qt-4.7.1. early versions work fine.
this bug looks very similar http://bugreports.qt.nokia.com/browse/QTBUG-15659
Attachments
Issue Links
- replaces
-
QTBUG-16430 QTextCursor reproducable crash
- Closed
-
QTBUG-15659 Regression: Lokalize crashes when using backspace
- Closed