Results 1 to 4 of 4

Thread: QModelIndexList access reading violation

  1. #1
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QModelIndexList access reading violation

    Hi,
    i have a table view in my application and I want remove the element selected.
    This is my code:


    Qt Code:
    1. QTableView tableView;
    2.  
    3. QItemSelectionModel * m_pxSelectionModel;
    4. QModelIndexList indexes;
    5.  
    6. if (m_pxSelectionModel != NULL)
    7. {
    8. m_pxSelectionModel = NULL;
    9. }
    10.  
    11. m_pxSelectionModel = tableView->selectionModel();
    12.  
    13. qDebug() << "List" << indexes;
    14. if (indexes.isEmpty())
    15. {
    16. indexes = m_pxSelectionModel->selectedRows();
    17. }else{
    18. indexes.clear();
    19. }
    20.  
    21. for (int j = 0; j < indexes.size(); j++)
    22. {
    23. index = indexes.at(j);
    24. int row = index.row();
    25. model->removeRows(row, 1, QModelIndex());
    26. }
    To copy to clipboard, switch view to plain text mode 

    At the first time work correctly and the selected row is cancelled. At the second time I have a problem: this is the message error:

    List (QModelIndex(0,0,0x71b2580,QStandardItemModel(0x37 fbff0) ) , QModelIndex(0,1,0x71b2580,QStandardItemModel(0x37f bff0) ) , QModelIndex(0,2,0x71b2580,QStandardItemModel(0x37f bff0) ) )
    First-chance exception at 0x76f5e23e in Test.exe: 0xC0000005: Access violation reading location 0x681012a8.
    Unhandled exception at 0x76f5e23e in Test.exe: 0xC0000005: Access violation reading location 0x681012a8.


    Can anyone help me please??

    Thanks, bye

  2. #2
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QModelIndexList access reading violation

    Some idea??

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QModelIndexList access reading violation

    The obvious:
    • Have you single-stepped it in your debugger?
    • Which line causes the access violation?
    • Is the model pointer valid at line 26?

    Other questions that might help;
    • Why are you doing the conditional dance with lines 7-10 and 15-20? Do you want the selection model and the rows or not?
    • How is it that indexes has something in it at line 14 before you initialise it at line 17 (sometimes)?
    • Are other model indexes in the list still valid after you delete a row?
    • Are you sure all the selected indexes have an invalid parent at line 26 (i.e. is the model a table model or a tree)?

  4. #4
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QModelIndexList access reading violation

    I have solved reimplementing my procedure and saving a pointer to the current item selected in the main table.

    Thanks for the reply, Bye

Similar Threads

  1. Replies: 6
    Last Post: 17th March 2010, 10:53
  2. OpenCV causes access violation only during timerEvent
    By derekkingston in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2010, 08:56
  3. Replies: 5
    Last Post: 17th June 2009, 14:01
  4. Access violation when reading big text files
    By robertson1 in forum General Programming
    Replies: 0
    Last Post: 18th September 2008, 06:59
  5. Access Violation on Signal Emit
    By khagzan in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2007, 22:51

Tags for this Thread

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.