QString text = "Hello World!"; QTextEdit editor; editor.setPlainText(text); QTextCursor cursor = editor.textCursor(); cursor.movePosition(QTextCursor::Left); cursor.deletePreviousChar(); editor.setTextCursor(cursor);
QString text = "I will delete the letter 'r'"; QTextDocument document(text); QTextCursor cursor = QTextCursor(&document); cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1); cursor.deletePreviousChar(); QString result = document.toPlainText();In this example, a QTextDocument is created and initialized with some text. A cursor is created and moved to the end of the document, then one position to the left with the KeepAnchor option, which selects the character being deleted. The deletePreviousChar function is then called and the resulting text is extracted from the document. Package library: QtGui.