Hello All,

I have a standard treeview model that contains checkboxes

I'm trying to get the current status of the checkbox when a user clicks on an item, this click could either be on that element, or on the checkbox (selecting or deselecting)

my problem is that its always giving me the previous status, not the current one, this is my code, and please see if you can help me figure how to solve this

I've tried connecting the below slot to the clicked(), activated(), and pressed() signal, and its always the same behavior

Qt Code:
  1. void myclass::treeViewClicked(QModelIndex index)
  2. {
  3. if(!index.isValid())
  4. return;
  5.  
  6. if(index.column() != 0)
  7. return;
  8.  
  9. ui->treeView->update(index);
  10.  
  11. if (ui->treeView->model()->data(index, Qt::CheckStateRole) == Qt::Checked)
  12. {
  13. qDebug() << "Selected";
  14. ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
  15. //ui->treeView
  16. }
  17. else
  18. {
  19. qDebug() << "NOTTTT Selected";
  20. ui->treeView->selectionModel()->select(index, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
  21. }
  22. }
To copy to clipboard, switch view to plain text mode 

even if i click on the checkbox, and select it, it will only show me the previous stat, not the current one

Thank you very much