Results 1 to 11 of 11

Thread: QModelIndexList crashes application on destruct

  1. #1
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default QModelIndexList crashes application on destruct

    Hello,

    I have a problem almost simular as in Thread 26498 Crash after selectionModel.

    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.

    Qt Code:
    1. msvcr90d.dll!operator delete(void * pUserData=0x088a6448) Line 52 + 0x51 bytes C++
    2. MBRSAGUI.dll!QModelIndex::`scalar deleting destructor'() + 0x32 bytes C++
    3. MBRSAGUI.dll!QList<QModelIndex>::node_destruct(QList<QModelIndex>::Node * from=0x0a194d8c, QList<QModelIndex>::Node * to=0x0a194d98) Line 359 + 0x2f bytes C++
    4. MBRSAGUI.dll!QList<QModelIndex>::free(QListData::Data * data=0x0a194d78) Line 553 C++
    5. MBRSAGUI.dll!QList<QModelIndex>::operator=(const QList<QModelIndex> & l=[0]()) Line 371 C++
    6. MBRSAGUI.dll!QList<QModelIndex>::clear() Line 561 + 0x24 bytes C++
    7. MBRSAGUI.dll!MBRSA_RSA_ScenePane::RemoveModelClickedGS() Line 713 C++
    8. MBRSAGUI.dll!MBRSA_RSA_ScenePane::qt_metacall(QMetaObject::Call _c=InvokeMetaMethod, int _id=7, void * * _a=0x0468c4b4) Line 175 + 0x8 bytes C++
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void Class::RemoveModelClickedGS ()
    2. {
    3. QItemSelectionModel *selectionModel = m_implantSelectionTableWidget->selectionModel();
    4. QModelIndexList indexes = m_selectionModel->selectedIndexes();
    5.  
    6. foreach(index, indexes)
    7. {
    8. m_implantModel->removeRows ((*it).row(), 1, (*it).parent());
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Has anyone an idea what causes the crash?

  2. #2
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: QModelIndexList crashes application on destruct

    It looks like I do link to the release libs of QT while the program is in Debug mode. Can that be a problem?

  3. #3
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: QModelIndexList crashes application on destruct

    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.

  4. #4
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QModelIndexList crashes application on destruct

    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.

  5. #5
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: QModelIndexList crashes application on destruct

    I submitted the bug to Nokia:

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

    Will test the update to 4.6.1. asap

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QModelIndexList crashes application on destruct

    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.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  7. #7
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QModelIndexList crashes application on destruct

    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?

  8. #8
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: QModelIndexList crashes application on destruct

    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:

    Qt Code:
    1. void Class::RemoveModelClickedGS ()
    2. {
    3. QItemSelectionModel *selectionModel = m_implantSelectionTableWidget->selectionModel();
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    Regards,

    Marcel

  9. #9
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: QModelIndexList crashes application on destruct

    Quote Originally Posted by euch View Post
    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.

  10. #10
    Join Date
    Feb 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QModelIndexList crashes application on destruct

    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.

  11. #11
    Join Date
    May 2010
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QModelIndexList crashes application on destruct

    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.

Similar Threads

  1. Application crashes when it has a particular name
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 20:50
  2. how to self-destruct a program
    By timmu in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2010, 10:42
  3. Application crashes
    By waynew in forum Newbie
    Replies: 1
    Last Post: 2nd November 2009, 10:31
  4. My application crashes
    By sophister in forum Qt Programming
    Replies: 13
    Last Post: 27th April 2009, 07:39
  5. Hot to get a QModelIndexList from a model?
    By brazso in forum Newbie
    Replies: 1
    Last Post: 16th January 2009, 12:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.