How to pass variables to slot methods in QT?

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

    You could try having your switchTab slot take no argument and use QObject::sender to get the object that sent the signal.

    Messenger::switchTab()
    {
      QObject* sender = this->sender();
      QPushButton* button = qobject_cast(sender);
      if(button)
      {
        // Do stuff...
      }
    }
    

提交回复
热议问题