PDA

View Full Version : QTextCursor::selectedText



evgenM
8th November 2007, 10:01
i have this code


TextEdit::TextEdit()
{
setPlainText("text1\ntext2");
select();
}
//
void TextEdit::select()
{
QTextCursor cursor = textCursor();
while (!cursor.atEnd())
{
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
}
cout <<qPrintable(cursor.selectedText())<<endl;
}


so my text is "text1\ntext2" but function select() return "text1?text2"
'?' it's unprintable Enter?
how to get text in normal mode with '\n' using QTextCursor?

jpn
8th November 2007, 11:30
QTextCursor::selectedText():

Note: If the selection obtained from an editor spans a line break, the text will contain a Unicode U+2029 paragraph separator character instead of a newline \n character. Use QString::replace() to replace these characters with newlines.

PS. Why not use QTextEdit::selectAll()?

evgenM
8th November 2007, 11:40
thanks
it's just example - i don't need select all text