I am trying to get the text from a text edit and store it in a QString .
When I write this
QString text = ui->textEdit->toPlainText();
it only reads the text before the first '\n' So how can I get the whole text with '\n's in it.
This is being called from a slot like this: -
void MainWindow::on_pushButton_clicked()
{
QString text = ui->textEdit->toPlainText();
ui->label_2->setText(text);
}
QTextEdit does not have any text() method, if you want to get the text you must use toPlainText() , if you want to clean the text it is better to use clear() since it makes it more readable.
If you want to provide your users with an editable rich text editor, use QTextEdit. If you want a text browser without hypertext navigation use QTextEdit, and use QTextEdit::setReadOnly() to disable editing. If you just need to display a small piece of rich text use QLabel.
QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML-style tags, or Markdown format. It is optimized to handle large documents and to respond quickly to user input. QTextEdit works on paragraphs and characters.
Using Rich Text You can use rich text in the Text and Text Input components. To open the rich text editor, select the (Edit) button in Properties > Character > Text.
Turning my comment into an answer
Make sure that the label is high enough to actually display multi-line text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With