C++ 如何从文本编辑 QT 中获取整个文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19427228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:48:48  来源:igfitidea点击:

How to get the whole text from text edit QT

c++qtuser-interface

提问by samvel1024

I am trying to get the text from a text edit and store it in a QString .

我正在尝试从文本编辑中获取文本并将其存储在 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.

它只读取第一个 '\n' 之前的文本 那么我怎样才能获得包含 '\n' 的整个文本。

This is being called from a slot like this: -

这是从这样的插槽调用的: -

void MainWindow::on_pushButton_clicked() 
{ 
    QString text = ui->textEdit->toPlainText(); 
    ui->label_2->setText(text); 
}

采纳答案by Angew is no longer proud of SO

Turning my comment into an answer

把我的评论变成答案

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

确保标签足够高以实际显示多行文本。