PDA

View Full Version : Crash after updating from Qt4.3 to Qt4.4.0-rc1



steg90
15th May 2008, 16:05
Hi all,

I've recently updated to Qt4.4.0-rc1 from Qt4.3, this has now given me a crash on one of my table views and I've debugged it down to the following bit of code :




modelIndex = m_pmodel->index( m_nAmount, 1, QModelIndex() );
m_pSpinBox[m_nAmount] = new QSpinBox(ui.tableView);
m_pSpinBox[m_nAmount]->setMinimum( 1 );
m_pSpinBox[m_nAmount]->setMaximum( 100 );
m_pSpinBox[m_nAmount]->setSingleStep( 10 );
m_pSpinBox[m_nAmount]->setSuffix("ms");
m_pSpinBox[m_nAmount]->setValue( this->m_MessObj.m_nAmount + 10 );
ui.tableView->setIndexWidget( modelIndex, m_pSpinBox[m_nAmount] );



The setIndexWidget causes the crash, I've not much idea why as this was fine in Qt4.3, maybe there is a bug in my code that was getting away on Qt4.3, I don't know?

m_nAmount is set to zero initiallty.

Anybody any ideas of what could be wrong?

Thanks,
Steve

jpn
15th May 2008, 17:03
I'd like to point out that 4.4.0 stable has been out for a week or two. You might want to try with that one..

steg90
15th May 2008, 17:09
Thanks JPN,

Just not had the time to install it.

It does seem though that it has something to do with the modelIndex.

For example, if I do :



modelIndex = m_pmodel->index( m_nAmount, 2, QModelIndex() );


Use index of 2 instead of 1, there is no crash?

Regards,
Steve

steg90
19th May 2008, 13:44
I've now installed Qt4.4.0 and I still get the same crash, I'm at a loss with this now, the code still crashes on the setIndexWidget line, this did not happen in Qt4.3.0.

Maybe there is something wrong with the code???

Any help is appreciated.

Thanks,
Steve

jpn
19th May 2008, 14:09
Could you show us the backtrace from a debugger?

steg90
19th May 2008, 14:21
Sure can,

Here is the actual line the crash ends up at :


inline int size() const { return d->size; }


Which is in qstring.h

Stack trace :

QtCored4.dll!QString::size() Line 84 + 0xa bytes

QtCored4.dll!QString::operator==(const QString & other={...}) Line 1738 + 0x12 bytes

QtGuid4.dll!QSpinBoxPrivate::validateAndInterpret( QString & input={...}, int & pos=0x0045ee74, QValidator::State & state=0x00083ec4) Line 1011 + 0x16 bytes

QtGuid4.dll!QSpinBox::validate(QString & text={...}, int & pos=0x0045ee74) Line 479 + 0x18 bytes

QtGuid4.dll!QAbstractSlider::setValue(int value=0x00d41668) Line 511

DACanMonitor.exe!SliderDelegate::setEditorData(QWi dget * editor=0x05901790, const QModelIndex & index={...}) Line 55

QtGuid4.dll!QAbstractItemView::dataChanged(const QModelIndex & topLeft={...}, const QModelIndex & bottomRight={...}) Line 2805

QtGuid4.dll!QAbstractItemView::setIndexWidget(cons t QModelIndex & index={...}, QWidget * widget=0x05901790) Line 2731


Regards,
Steve

jpn
19th May 2008, 14:51
Can we see SliderDelegate::setEditorData() implementation?

steg90
19th May 2008, 15:01
Of course,



void SliderDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
switch( index.column() )
{
case 1:
{
int value = index.model()->data(index, Qt::DisplayRole).toInt();
QSlider *spinBox = static_cast<QSlider*>(editor);
spinBox->setValue(value);
break;
}
case 0:
{
QString value = index.model()->data(index, Qt::DisplayRole).toString();
QCheckBox *checkbox = static_cast<QCheckBox*>(editor);
if( value == "1" )
checkbox->setCheckState( Qt::Checked );
else
checkbox->setCheckState( Qt::Unchecked );
break;
}
}
}


Looks like it is a simple case of checking whether value is zero in case 1.

Kind regards,
Steve

jpn
19th May 2008, 17:48
Looks like you static_cast something, which is not a QSpinBox, as QSpinBox. Rewrite it as using dynamic_cast or qobject_cast and check the return value.