PDA

View Full Version : emitting signals in const function



maxel
19th October 2008, 14:12
Hey there,
i have written a ComboBoxDelegate an want to emit a signal in a const function. VusualC++ returns the Error
"error C2662: 'ComboBoxDelegate::currentIndexChanged': this-pointer cann't be changed from 'const ComboBoxDelegate' in 'ComboBoxDelegate &'"

Anny ideas?

void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if(index.isValid()&&index.column()==ViewSpalte)
{
QComboBox* combo = qobject_cast<QComboBox*>(editor);
int idx=combo->currentIndex();
int nidx=index.model()->data(index,Qt::DisplayRole).toInt();
combo->setCurrentIndex(nidx);
if(idx!=nidx)
emit currentIndexChanged(nidx); // the Error occurs here
}
else
QItemDelegate::setEditorData(editor, index);
}

caduel
19th October 2008, 14:31
have you tried declaring the signal as const, too?

maxel
19th October 2008, 14:51
Thank's, thats it! Its too simple. sorry

wysota
19th October 2008, 16:05
Emitting a "currentIndexChanged" signal from setEditorData is probably a design flaw regardless of constness.