How to pass variables to slot methods in QT?

Posted by Neko on Stack Overflow See other posts from Stack Overflow or by Neko
Published on 2011-02-07T23:20:52Z Indexed on 2011/02/07 23:25 UTC
Read the original article Hit count: 196

Filed under:
|
|

Hi.

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 QPushButtons, which all represent a different channel. These buttons are made with the following method, and that's where my problem kicks in:

void Messenger::addToActivePanels(std::string& channel)
{
    activePanelsContents = this->findChild<QWidget *>(QString("activePanelsContents"));
    pushButton = new QPushButton(activePanelsContents);
    pushButton->setObjectName("pushButton");
    pushButton->setGeometry(QRect(0, 0, 60, 60));
    pushButton->setText("");
    pushButton->setToolTip(QString(channel.c_str()));
    pushButton->setCheckable(true);
    pushButton->setChecked(false);
    connect(pushButton, SIGNAL(clicked()), this, SLOT(switchTab(channel)));
}

(activePanelContents is a QWidget that holds the list.)

The point is that each button should call the switchTab(string& tabname) method when clicked, including the specific channel's name as variable. This implementation doesn't work though, and I haven't been able to find out how to properly do this, even after reading several pages on it on the internet.

Can anybody please tell me how to do this? It'd be greatly appreciated, as always. :)

© Stack Overflow or respective owner

Related posts about c++

Related posts about qt