QTextEdit* textEdit = new QTextEdit(); QTextCursor cursor = textEdit->textCursor(); cursor.beginEditBlock(); cursor.insertText("Hello World!"); cursor.insertText("This is a test."); cursor.endEditBlock();
QTextEdit* textEdit = new QTextEdit(); QTextCursor cursor = textEdit->textCursor(); cursor.beginEditBlock(); cursor.clearSelection(); cursor.insertText("New Text"); cursor.endEditBlock();In this example, we create a QTextEdit widget and begin an editing block with beginEditBlock(). We then clear any previous selection with clearSelection() and insert some new text with insertText(). We then end the editing block with endEditBlock(). Package library: Qt C++ library.