How to add a parameter to a slot
Hello,
This is the first time I use Qt and I need an advice to perform the following task.
With this loop, I display a combobox on each column of the first row of my QTableWidget.
Code:
for (int col=0 ; col <= colonnes ; ++col)
{
moncombo->addItems(PL_variables);
TableW->setCellWidget(0, col, moncombo);
connect(moncombo, SIGNAL(activated(int)),this, SLOT(associate(int)));
}
With connect(moncombo, SIGNAL(activated(int)),this, SLOT(associate(int))); I can transmet the index of the combo to the slot.
My problem is that I also have to transmet the number of the column on which the signal had been sent.
I guess I should to use the horizontalHeader function or something like that, but I don't really know how to do this.
Thanks
Re: How to add a parameter to a slot
You could use QSignalMapper for this.
Re: How to add a parameter to a slot
Thanks for your quick answer Marcel. I didn"t know this class yet, I read the documentation right now...
Re: How to add a parameter to a slot
It would probably be wiser to use a custom delegate instead of cell widgets. It'll get awfully slow if you have more than 10 of them.
Re: How to add a parameter to a slot
Thank you for your advise Wysota. I'm currently learning Qt and custom delegates is the next chapter for me :o Normaly, they are only 8 of them, so it's not to slow to execute.
I could finaly manage to retrieve the number of column as follow :
Code:
for (int col=0 ; col <= colonnes ; ++col)
{
moncombo->addItems(PL_variables);
moncombo
->setObjectName
(QString::number(col
));
// the name of my combo is the number of my column TableW->setCellWidget(0, col, moncombo);
connect(moncombo, SIGNAL(activated(int)),this, SLOT(associate(int)));
}
The slot
Code:
void MainWindow::associate(int index)
{...
int c = sender()->objectName().toInt();
...}
Regarding to the documentation, it's not a very correct way to do this... That's why I try to implement another solution using QSignalMapper.
Thanks for your advices...