How to get the whole text from text edit QT
Asked Answered
B

1

19

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); 
}
Bonner answered 17/10, 2013 at 12:49 Comment(4)
What is the text in your text edit? Does "line1\nline2" work?Prospero
no I only see line1 in the labelBonner
Saying \n I mean going to a new line (pressing Enter)Bonner
Is the label high enough, or allowed to expand vertically? If you print the text to the console or a file, is it also truncated?Macassar
M
11

Turning my comment into an answer

Make sure that the label is high enough to actually display multi-line text.

Macassar answered 17/10, 2013 at 13:33 Comment(2)
What do you mena high enough?Ashbey
@ZdravkoDonev That it has sufficient height.Macassar

© 2022 - 2024 — McMap. All rights reserved.