How to pass variables to slot methods in QT?

后端 未结 6 1313
长情又很酷
长情又很酷 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:05

    Don't use the sender method unless you absolutely have to. It ties the function directly to being used only as a slot (can't be called directly). Retain the behavior of having the function accept a string and simply make a mechanism by which you can call it.

    One method, among others you might find, is to leverage use of QSignalMapper. It will map objects to values and regenerate signals of the appropriate signature.

提交回复
热议问题