PDA

View Full Version : cursor.atEnd returns true, cursor is at start?



JuKu
2nd October 2009, 15:08
I am clearly doing something stupid that a newbie does, but I can't solve this. Here is my test code:

ui->TextEdit->setPlainText("testing\n");
QTextCursor cursor( ui->TextEdit->textCursor() );
cursor.movePosition (QTextCursor::End, QTextCursor::MoveAnchor);
if(cursor.atEnd())
{
ui->TextEdit->insertPlainText("true\n");
};

This prints:

true
testing

I would expect the lines in different order. What am I missing? :confused:

Grimlock
2nd October 2009, 15:24
The Qt doc clearly states.

QTextCursor QTextEdit::textCursor () const

Returns a copy of the QTextCursor that represents the currently visible cursor. Note that changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to update the visible cursor.

just use the moveCursor method form QTextEdit :p

JuKu
2nd October 2009, 15:32
I did read the documentation, but clearly from a wrong place. Besides, you can't always rely on snippets from the Internet, as demonstrated. Thanks for pointers! :o