I have a bunch of QComboBox es in a table. To let me know which one was running, I reassign the signal to encode the location of the table cell (as described in Choosing a QComboBox in a QTableWidget )
(Why Qt doesnβt just send a cell activation signal first, so you can use the same current row / column mechanism as any other cell editing that I donβt know.)
But this eliminates all knowledge of the original sender widget. Calling QComboBox* combo = (QComboBox* )sender() in the slot fails, presumably because sender() now QSignalMapper .
I can use the encoded row / column to search for QComboBox in table widgets, but this seems wrong. Is there a better way to do this?
eg:.
// in table creator _signalMapper = new QSignalMapper(this); // for each cell QComboBox* combo = new QComboBox(); connect(combo, SIGNAL(currentIndexChanged(int)), _signalMapper, SLOT(map())); _signalMapper->setMapping(combo, row); // and finally connect(_signalMapper, SIGNAL(mapped(int)),this, SLOT(changedType(int))); // slot void myDlg::changedType(int row) { QComboBox* combo = (QComboBox* )sender(); // this doesn't work !! }
EDIT . Added for future search: Mark Summerfield's new book, Advanced Qt Programming , explains how to do this.
source share