PDA

View Full Version : QModelIndexList crashes application on destruct



mstegehu
2nd February 2010, 15:14
Hello,

I have a problem almost simular as in Thread 26498 Crash after selectionModel (http://www.qtcentre.org/threads/26498-application-crushes-after-performing-selectionModel()-from-tableView).

I have a QTableView with custom Model and custom delegate. For adding and deleting rows I added two buttons and created a slot that calls the CustomModel to delete the row. I get a crash when the slots exits. It looks like a problem with the QModelIndexList.



msvcr90d.dll!operator delete(void * pUserData=0x088a6448) Line 52 + 0x51 bytes C++
MBRSAGUI.dll!QModelIndex::`scalar deleting destructor'() + 0x32 bytes C++
MBRSAGUI.dll!QList<QModelIndex>::node_destruct(QList<QModelIndex>::Node * from=0x0a194d8c, QList<QModelIndex>::Node * to=0x0a194d98) Line 359 + 0x2f bytes C++
MBRSAGUI.dll!QList<QModelIndex>::free(QListData::Data * data=0x0a194d78) Line 553 C++
MBRSAGUI.dll!QList<QModelIndex>::operator=(const QList<QModelIndex> & l=[0]()) Line 371 C++
MBRSAGUI.dll!QList<QModelIndex>::clear() Line 561 + 0x24 bytes C++
MBRSAGUI.dll!MBRSA_RSA_ScenePane::RemoveModelClick edGS() Line 713 C++
MBRSAGUI.dll!MBRSA_RSA_ScenePane::qt_metacall(QMet aObject::Call _c=InvokeMetaMethod, int _id=7, void * * _a=0x0468c4b4) Line 175 + 0x8 bytes C++





void Class::RemoveModelClickedGS ()
{
QItemSelectionModel *selectionModel = m_implantSelectionTableWidget->selectionModel();
QModelIndexList indexes = m_selectionModel->selectedIndexes();

foreach(index, indexes)
{
m_implantModel->removeRows ((*it).row(), 1, (*it).parent());
}
}


Has anyone an idea what causes the crash?

mstegehu
2nd February 2010, 15:26
It looks like I do link to the release libs of QT while the program is in Debug mode. Can that be a problem?

mstegehu
3rd February 2010, 15:30
Tried the workaround suggested in Thread 26498 Crash after selectionModel:

Link debug application with debug libraries of QT. No crash anymore.

But I see no reason why I could not use the release libraries of QT.

psih128
3rd February 2010, 16:05
Maybe some piece of memory that had been allocated with debug code, and thus debug CRT, was deleted with release code linked against release CRT, this usually leads to crashes.

mstegehu
5th February 2010, 13:29
I submitted the bug to Nokia:

http://bugreports.qt.nokia.com/browse/QTBUG-7884

Will test the update to 4.6.1. asap

faldzip
5th February 2010, 16:25
your code doesn't make sense. what is it? and what is more it is not supposed to work at all. If you have 4 item in your model and 2nd and 3rd is selected, then after removing 2nd item others are invalid, because you have 3rd item left to remove and it has row() == 2, but after 2 item removal (it had row() == 1) now the "previously 3rd" item is "currently 2nd" item so you will in fact remove "previously 4th" item which is not what you want I think.

euch
6th February 2010, 08:36
Hello;

I have the same problem.

How can I see that the release libs are linked to my application when I am in debug mode. I enter to the properties of the application and looked in the link page under input entry but I didn't notice anything wrong.

by the way, what is the best way to delete selected items in QListView?

mstegehu
9th February 2010, 09:40
faldżip: You are right and you probably also guessed that it would mean iterator and the foreach loop was a for loop before. Would not matter as the code below crashes too:



void Class::RemoveModelClickedGS ()
{
QItemSelectionModel *selectionModel = m_implantSelectionTableWidget->selectionModel();
}


But reffering to you remark it is better to remove from back to front to prevent index problems.

Regards,

Marcel

mstegehu
9th February 2010, 10:49
Hello;

I have the same problem.

How can I see that the release libs are linked to my application when I am in debug mode. I enter to the properties of the application and looked in the link page under input entry but I didn't notice anything wrong.

In MSVS -> Project Properties - Configuration Properties -> Linker -> Input -> Additional Dependencies ->

If you look at the added libraries: QtCored4.lib is the debug version QtCore4.lib is the release version.

And of course with Dependency Walker you can see it.

euch
12th February 2010, 06:42
I looked at the Additional Dependencies and I notice that all my libs are debug libs (with d extension), but still my application is crashed if I use the line code
QItemSelectionModel *pSlectionModel = pTableWidget->selectionModel();
In release mode the application not crashing, so I used the _DEBUG macro to distinguish the two cases.

thierryB
19th May 2010, 08:58
YOu can't mix debug and release library. They're not compatible. They each have their version of the runtime.

In addition the vcproj file is very well done and if you want to switch from debug to release (and vice versa) just use the appropriate combobox on the toolbar and everything should be fine.