Hello,

I try to detect cases where there is a selection or none, on a QTableView which allows single rows selection.

What's wrong? Code below doesn't fail, but I don't get the popups "xLogWarning()" calls should produce...

I'm also wondering about the model giving me its value for selected row and column of my choice...

I also read this topic: http://www.qtcentre.org/threads/1046...t-selected-row

Thanks for helping.

Qt Code:
  1. m_tableView = new QTableView();
  2. m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
  3. m_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. // Get selected image
  2. QItemSelectionModel* selectedModel = m_tableView->selectionModel();
  3. if(!selectedModel->hasSelection()) {
  4. xLogWarning(tr("No image selected"));
  5. return;
  6. }
  7. xLogWarning(tr("There is an image selected"));
  8. QModelIndexList selection = selectedModel->selectedIndexes();
  9. xLogWarning(tr("selected row: %1").arg(selection[0].row()));
  10. xLogWarning(tr("Selected image: %1").arg(m_model.getObjectIdAt(selection[0].row())));
To copy to clipboard, switch view to plain text mode