I have subclassed QAbstractItemModel and trying to retrieve a widget in slot of dataChanged signal.
connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(slotDataChanged(const QModelIndex&, const QModelIndex&)));
void MyEditor::slotDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
QComboBox* widget = dynamic_cast<QComboBox*>(sender());
if (widget)
{
// do something
}
}
Here I am getting a null widget everytime, same result with qobject_cast.
I am setting combobox widget in my tableview a delegate class which derives QStyledItemDelegate.
MyDelegate* myDelegate;
myDelegate = new MyDelegate();
tableView->setItemDelegate(myDelegate);
tableView->setModel(model);
QWidget* MyDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QComboBox* cb = new QComboBox(parent);
cb->addItem(QString("All"));
cb->setCurrentIndex(0);
return cb;
}
How can I obtain sender object in this case? Thanks.