QModelIndexList access reading violation
Hi,
i have a table view in my application and I want remove the element selected.
This is my code:
Code:
QModelIndexList indexes;
if (m_pxSelectionModel != NULL)
{
m_pxSelectionModel = NULL;
}
m_pxSelectionModel = tableView->selectionModel();
qDebug() << "List" << indexes;
if (indexes.isEmpty())
{
indexes = m_pxSelectionModel->selectedRows();
}else{
indexes.clear();
}
for (int j = 0; j < indexes.size(); j++)
{
index = indexes.at(j);
int row = index.row();
}
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
Re: QModelIndexList access reading violation
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)?
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