Qt,QTextEdit:如何删除最后一个字符?

Lin*_*umz 0 c++ qt qtextedit

我在我的C++ GUI应用程序中使用QTextEdit,我使用textEdit-> append(byteArray); 添加一些文本,不幸的是append()在每次调用append()后在最后添加一个新行字符.我知道我可以使用insertPlainText(),它不会添加新行字符,但在处理大文档时会占用更多内存.

谢谢你的帮助!

Tro*_*our 8

自从文档QTextEdit::insertPlainText

它相当于

edit->textCursor().insertText(text);
Run Code Online (Sandbox Code Playgroud)

我会假设你可以做类似的事情

edit->textCursor().deletePreviousChar();
Run Code Online (Sandbox Code Playgroud)

如果需要,您可以先清除任何选择

edit->textCursor().clearSelection();
Run Code Online (Sandbox Code Playgroud)