I subclassed QItemDelegate::setModelData() and I am now getting multiple calls into it when the QTableWidgetItem loses focus. The end result is a crash in a moc_** file when pressing 'Enter'.

Mouse-clicking, Tab and Enter all cause a double entry into the setModelData() function. Only the Enter key causes a crash.

I am baffled. Can anyone see something wrong with my implementation of setModelData()?

Qt Code:
  1. int Table::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
  2. {
  3. --->_id = QTableWidget::qt_metacall(_c, _id, _a);
  4. . . .
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void DMXTableCellDelegate::setModelData( QWidget* editor, QAbstractItemModel* model,
  2. const QModelIndex& index ) const
  3. {
  4. if ( index.column() == COL_Name )
  5. {
  6. QLineEdit* lineEdit = qobject_cast<QLineEdit*>( editor );
  7.  
  8. // Validate the Name string
  9. if ( (lineEdit != NULL) || !lineEdit->text().isEmpty() )
  10. {
  11. QString sTypedName = lineEdit->text();
  12.  
  13. // Substitute for illegal characters
  14. QString sNewName = "";
  15. bool bIsValid = true;
  16. QChar c;
  17.  
  18. for ( int i = 0; i < sTypedName.length(); i++ )
  19. {
  20. c = sTypedName.at( i );
  21.  
  22. if ( (c == '(') || (c == '<') )
  23. {
  24. c = '[';
  25. bIsValid = false;
  26. }
  27. else if ( (c == ')') || (c == '>') )
  28. {
  29. . . .
  30. }
  31.  
  32. sNewName.append( c );
  33. }
  34.  
  35. if ( !bIsValid )
  36. {
  37. QString sOrigName = index.data( Qt::EditRole ).toString();
  38.  
  39. int rVal = QMessageBox::warning( qobject_cast<QWidget*>( m_parent ),
  40. "Restricted Characters Found"),
  41. "Message String"),
  42. QMessageBox::Ok, QMessageBox::Cancel );
  43. if ( rVal == QMessageBox::Cancel )
  44. model->setData( index, QVariant( sOrigName ) );
  45. else
  46. model->setData( index, QVariant( sNewName ) );
  47. }
  48. }
  49.  
  50. return;
  51. }
  52.  
  53. QItemDelegate::setModelData( editor, model, index );
  54. }
To copy to clipboard, switch view to plain text mode