简体   繁体   English

如何从 QTabWIdget C++ 读取 textedit 对象的文本?

[英]How to read text of textedit object from QTabWIdget C++?

I have called same TextEdit object whenever new tab is created.每当创建新选项卡时,我都会调用相同的TextEdit对象。 But the text on other tabs are inaccessible.但是其他选项卡上的文本无法访问。 How can I get the text from other TextEdit that are opened in new tabs.如何从在新选项卡中打开的其他TextEdit获取文本。

I am trying to save text in a file.我正在尝试将文本保存在文件中。

same TextEdit in every new tab每个新选项卡中的相同TextEdit

1

void MainWindow::on_actionsavew_triggered()
{
    QString file_name = QFileDialog::getSaveFileName(this,"Open the file","X://");
        QFile file(file_name);
        if(!file.open(QFile::WriteOnly | QFile::Text)){
            QMessageBox::warning(this,"Error","File not Open");
            return;
        }
        QTextStream out(&file);
        QString text = ui->textEdit->toPlainText();
       out<<text;
       file.flush();
       file.close();
}

this here这里

QString text = ui->textEdit->toPlainText();

is aa hint to us indicating that you are actually adding those widgets to the tabs and windows using the qt designer in qt creator, therefore you can access ANY widget and its attributes using the same approach是对我们的暗示,表明您实际上是使用 qt creator 中的 qt 设计器将这些小部件添加到选项卡和窗口中,因此您可以使用相同的方法访问任何小部件及其属性

eg例如

do

QString textFromTab1 = ui->textEditInTab1->toPlainText();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM