PDA

View Full Version : QTextEdit and cursor



newplayer
29th July 2008, 20:38
I have QTextEdit "textbox".
I want to do this:
Somebody is writing something in this QTextEdit "textbox". next he is clicking button, program is taking line by line text from QTextEdit and program throwing line by line to the list text which somebody have written , next program is sorting lines of text and program is showing sorted lines of text in QTextEdit.

I made it that:


QStringList list;
QString line;

QTextCursor cursor(textbox->textCursor());

cursor.movePosition(QTextCursor::End);
int end = cursor.position();

cursor.movePosition(QTextCursor::Start);
int start = cursor.position();



for(int i=start; i<end; i=cursor.position())
{
line=........ ? // <- I must take here present line of text
list.push_back(line);
cursor.movePosition(QTextCursor::Down);
cursor.movePosition(QTextCursor::StartOfLine);
}



Is it ok ? It is something new for me. How can I take all present line of text to throw it to the list ?

jacek
31st July 2008, 00:24
You can get the text through QTextCursor::selectedText(), but first you have to select it. You do that by calling movePosition() with QTextCursor::KeepAnchor as the second parameter.