How to pass variables to slot methods in QT?

后端 未结 6 1309
长情又很酷
长情又很酷 2021-02-14 04:19

I\'m making a little chat messenger program, which needs a list of chat channels the user has joined. To represent this list graphically, I have made a list of QPushButton

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 05:16

    if you're using Qt5, you can do it through lambda:

    connect( sender, &Sender::valueChanged,  [=](){ myMethod(5); } );
    
    void myMethod(int value)
    {
      // do stuff
    }
    

提交回复
热议问题