0

I have a Qt project that has a UI with many QLineEdits and one QTextEdit. I just want to merge the input of the individual QLineEdits into the QTextEdit. For example: when someone types in the first QLineEdit, I want the QTextEdit's first line to match. If someone types something in the 13th QLineEdit, the QTextEdit's 13th line should update to match. If a line editor is empty, the text editor's same lines will be empty too. Thanks.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42
  • and, is the `QTextEdit` editable too? – Mike May 14 '16 at 15:11
  • Actually I don't need any special edits on this Text, the lineedit's index is enough for me. So I can use not editable text too. I only need the index of those QLineedit but I don't know how to merge them. – Qqcolorspace May 14 '16 at 15:15

1 Answers1

0

you can have a UpdateTextEdit slot in your window/dialog's class, like this:

void ExampleDialog::UpdateTextEdit(){
    QString str= ui->lineEdit1->text();
    str+= "\n";
    str+= ui->lineEdit2->text();
    str+= "\n";
    str+= ui->lineEdit3->text();
    str+= "\n";
    ...
    //add text from all your line edits
    ...

    ui->textEdit->setPlainText(str);
}

and in the dialog/window's constructor, connect textChanged signal from all your QLineEdits to the UpdateTextEdit() slot, like this:

ExampleDialog::ExampleDialog(QWidget* parent):QDialog(parent),...{
    ...
    ...
    connect(ui->lineEdit1, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateTextEdit()));
    connect(ui->lineEdit2, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateTextEdit()));
    connect(ui->lineEdit3, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateTextEdit()));
    ...
}
Mike
  • 8,055
  • 1
  • 30
  • 44