0
QPushButton * colorBtns[8];

for (int i = 0; i < 8; i++)
{
    colorBtns[i] = new QPushButton(this);
    /* Stuff... */
    connect(colorBtns[i], &QPushButton::clicked, [=] () {
        cout << "Hello World!" << endl;
    });
}

I'm trying to connect buttons to lambda function by this way, but it doesn't react to my clicks. What i do wrong?

nick_redwill
  • 43
  • 1
  • 6
  • 1
    Please edit your question to provide a [mcve] and clarify what you mean by `"it doesn't work"`. Also, why `i < 7` rather than `i < 8` in this case? – G.M. Mar 11 '21 at 19:37
  • @G.M. Sorry my mistake, I corrected – nick_redwill Mar 11 '21 at 19:40
  • Do you interact with these buttons somehow inside the `/* Stuff ... */` section? I tried it on **gcc 10.2.0**, **Qt 5.15.2** and it works – Alloces Mar 11 '21 at 20:36
  • Make sure You are not double initializing Your buttons somewhere. I have had a similiar problem once, [take a look](https://stackoverflow.com/questions/63893177/qt5-qpushbuttons-cant-be-clicked). – sweak Mar 11 '21 at 21:03

0 Answers0