0

How can i make one form unique for different buttons? For example:

QVector<QString> text { "Iter FIRST", "Iter SECOND" };
for(size_t i = 0; i < 2; ++i)
{
     Form2 * form2 = new Form2(); //creating form
     connect(this, &MainWindow::SendCurretIteration, fitr, 
              &CurrentIterationForm::ShowCurrentIteration);//connect to the second form`

      emit MainWindow::SendCurretIteration(text[i]);
     QPushButton *btnShowForm = new QPushButton(this);
     btnShowForm->setGeometry(i + 40, i + 100, 50, 50);
     connect(btnShowForm, &QPushButton::clicked, this, [=]()
     {
         form2->show();
     });
}//end for()

And what i see by clicking on each button? ->Iter SECOND by clicking on button 1. ->Iter SECOND by clicking on button 2.

How to fix?

ymoreau
  • 3,402
  • 1
  • 22
  • 60
Nick Brian
  • 53
  • 5
  • I've missed 'form2' here: connect(this, &MainWindow::SendCurretIteration, form2, &CurrentIterationForm::ShowCurrentIteration);//connect to the second form` – Nick Brian Jul 26 '18 at 11:28
  • If you need one form for both buttons you need to take `Form2 * form2 = new Form2()` out of `for` loop. – vahancho Jul 26 '18 at 11:29
  • No, i want to see "Iter FIRST" by clicking on button 1 and "Iter SECOND" by clicking on the button 2. – Nick Brian Jul 26 '18 at 11:31
  • What is `Form2` ? Your design is very unclear, what is doing the slot `CurrentIterationForm::ShowCurrentIteration` ? What widgets and layout does contain `Form2` ? How did you try to display the text **Iter FIRST** in your GUI ? – ymoreau Jul 27 '18 at 09:41

0 Answers0