Hi,
i have a table view in my application and I want remove the element selected.
This is my 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();
}
QTableView tableView;
QItemSelectionModel * m_pxSelectionModel;
QModelIndexList indexes;
QModelIndex index;
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();
model->removeRows(row, 1, QModelIndex());
}
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
Bookmarks