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()?
int Table
::qt_metacall(QMetaObject::Call _c,
int _id,
void **_a
) {
. . .
int Table::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
--->_id = QTableWidget::qt_metacall(_c, _id, _a);
. . .
To copy to clipboard, switch view to plain text mode
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit
= qobject_cast<QLineEdit
*>
( editor
);
// Validate the Name string
if ( (lineEdit != NULL) || !lineEdit->text().isEmpty() )
{
QString sTypedName
= lineEdit
->text
();
// Substitute for illegal characters
bool bIsValid = true;
for ( int i = 0; i < sTypedName.length(); i++ )
{
c = sTypedName.at( i );
if ( (c == '(') || (c == '<') )
{
c = '[';
bIsValid = false;
}
else if ( (c == ')') || (c == '>') )
{
. . .
}
sNewName.append( c );
}
if ( !bIsValid )
{
QString sOrigName
= index.
data( Qt
::EditRole ).
toString();
int rVal
= QMessageBox::warning( qobject_cast<QWidget
*>
( m_parent
),
"Restricted Characters Found"),
"Message String"),
model
->setData
( index,
QVariant( sOrigName
) );
else
model
->setData
( index,
QVariant( sNewName
) );
}
}
return;
}
}
void DMXTableCellDelegate::setModelData( QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index ) const
{
if ( index.column() == COL_Name )
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>( editor );
// Validate the Name string
if ( (lineEdit != NULL) || !lineEdit->text().isEmpty() )
{
QString sTypedName = lineEdit->text();
// Substitute for illegal characters
QString sNewName = "";
bool bIsValid = true;
QChar c;
for ( int i = 0; i < sTypedName.length(); i++ )
{
c = sTypedName.at( i );
if ( (c == '(') || (c == '<') )
{
c = '[';
bIsValid = false;
}
else if ( (c == ')') || (c == '>') )
{
. . .
}
sNewName.append( c );
}
if ( !bIsValid )
{
QString sOrigName = index.data( Qt::EditRole ).toString();
int rVal = QMessageBox::warning( qobject_cast<QWidget*>( m_parent ),
"Restricted Characters Found"),
"Message String"),
QMessageBox::Ok, QMessageBox::Cancel );
if ( rVal == QMessageBox::Cancel )
model->setData( index, QVariant( sOrigName ) );
else
model->setData( index, QVariant( sNewName ) );
}
}
return;
}
QItemDelegate::setModelData( editor, model, index );
}
To copy to clipboard, switch view to plain text mode
Bookmarks