QTextEdit *textEdit = new QTextEdit(this); QTextCursor cursor = textEdit->textCursor(); cursor.removeSelectedText();
QTextDocument *doc = new QTextDocument(); QTextCursor cursor(doc); cursor.movePosition(QTextCursor::End); cursor.insertText("hello world\n"); cursor.movePosition(QTextCursor::Start); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 5); cursor.removeSelectedText();This example creates a new QTextDocument object and initializes a cursor at its end. Then it adds a new line text "hello world\n" to the document and moves the cursor to the start position. After that, it selects the first five characters of the text "hello" using the movePosition method and removes them using the removeSelectedText method. Package library: Qt core.