In the following code, why am I getting size 4 for QModelIndexList if I click in one file or directory only? How can I get only one path? I know I could use [0] but is there another way to get size 1?

Qt Code:
  1. // fsModel = QFileSystemModel
  2. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
  3. {
  4. ui->setupUi(this);
  5. const QString rootPath = "/home/rob/";
  6.  
  7. fsModel = new QFileSystemModel(this);
  8. fsModel->setRootPath(rootPath);
  9. ui->treeView->setModel(fsModel);
  10. ui->treeView->setRootIndex(fsModel->index(rootPath));
  11. }
  12.  
  13. void MainWindow::on_buttonCompress_clicked()
  14. {
  15. QModelIndexList list = ui->treeView->selectionModel()->selectedIndexes();
  16.  
  17. qDebug() << list.size();
  18.  
  19. for (const QModelIndex &modelIndex: list)
  20. qDebug() << fsModel->filePath(modelIndex);
  21.  
  22. // I wouldn't like to use []. I would like to get only one filepath, the one I selected.
  23. qDebug() << fsModel->filePath(list[0]);
  24. }
To copy to clipboard, switch view to plain text mode