QString str = ui->textedit->toPlainText(); // 这是普通文本
QString str = ui->textedit->toHtml(); // 这是富文本,即获取的是Html字符串
如果设置文本的话则对应的是:
ui->textedit->setPlainText("123");
ui->textedit->setHtml("123");
连接document ()的contentsChange信号:
void QTextDocument::contentsChange ( int position, int charsRemoved, int charsAdded ) [signal]
This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.
Information is provided about the position of the character in the document where the change occurred, the number of characters removed (charsRemoved), and the number of characters added (charsAdded).
The signal is emitted before the document's layout manager is notified about the change. This hook allows you to implement syntax highlighting for the document.
See also QAbstractTextDocumentLayout::documentChanged() and contentsChanged().
ui->textEdit->toPlainText()