Hi guys!
I have a QTableview with a model that displays data in a form. When user changes data and changes the row, I display a message asking if he wants to leave the record without saving it, set the current index to the previous one and return. Like this:
{
if (cardChanged)
{
{
cardChanged = false;
cardsTableView->setCurrentIndex(previous);
cardChanged = true;
return;
}
}
}
}
connect(cardsTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(changingCard(QModelIndex, QModelIndex)));
void MainWindow::changingCard(const QModelIndex ¤t, const QModelIndex &previous)
{
if (cardChanged)
{
if (QMessageBox::question(this, qApp->applicationName(), "Do you want to leave without saving?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
{
cardChanged = false;
cardsTableView->setCurrentIndex(previous);
cardChanged = true;
return;
}
}
}
}
To copy to clipboard, switch view to plain text mode
Problem is that it doesn't work. The form doesn't change but the row does. It appears that the mouse click it's executed after the setCurrentIndex(previous), so it changes anyway.
Ideas?
Thanks!
Bookmarks