-4

I have two buttons and one user form interface: Form2. I want to see different text creating form2. Lets see 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::SendCurretText, form2, 
              &Form2::ShowText);//connect to the second form`(textEdit)
      emit MainWindow::SendCurretText(text[i]);
 QPushButton *btnShowForm = new QPushButton(this);
 btnShowForm->setGeometry(i + 40, i + 100, 50, 50);
 connect(btnShowForm, &QPushButton::clicked, this, [=]()
 {
     form2->show();
 });
}//end for()

RESULT:
By clicking on button 1 i see "Iter SECOND"
By clicking on button 2 i see "Iter SECOND"

EXPECTED RESULT:
By clicking on button 1 i see "Iter FIRST"
By clicking on button 2 i see "Iter SECOND"

Joe
  • 9
  • 1

1 Answers1

0

++i is not i++. Try this:

QStringList text; text << "Iter FIRST" <<  "Iter SECOND";
for(qint32 i = 0; i < 2; i++)
{
     Form2 * form2 = new Form2(); //creating form
     connect(this, &MainWindow::SendCurretText, form2, 
              &Form2::ShowText);//connect to the second form`(textEdit)

     emit MainWindow::SendCurretText(text.at(i));

     QPushButton *btnShowForm = new QPushButton(this);
     btnShowForm->setGeometry(i + 40, i + 100, 50, 50);

     connect(btnShowForm, &QPushButton::clicked, this, [=](){ form2->show(); } );
}//end for()
Phiber
  • 1,041
  • 5
  • 17
  • 40