I have a scenario where I am asking the user for a number between 1 and 10 and creating that number of buttons of the type QPushButton
. I then want to create a function such that when I click the button the number on the button gets printed.
CodePudding user response:
Just use a lambda function like this:
for (int i = 1; i < numButtons; i )
{
QPushButton *btn = new QPushButton(...);
connect(btn, &QPushButton::clicked, [=]() {
// Do something with 'i'
}
}