0

Okay, I have the following code:

 QFileSystemModel *model = new QFileSystemModel;
 model->setRootPath(QDir::currentPath());
 model->setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot |
                  QDir::Readable | QDir::Writable | QDir::CaseSensitive );

 ui->fileList->setModel(model);
 ui->fileList->setRootIndex(model->index(QDir::currentPath()));

How can I find out which item (specifically, its corresponding filename) has been selected? I want the user to select a file using the mouse, such that the selected filename can be passed to a method I have.

RacerNerd
  • 1,579
  • 1
  • 13
  • 31

1 Answers1

1

Are you using QTreeWidget? It has an abstract item model. You need to get the model index from the selected item

spraff
  • 32,570
  • 22
  • 121
  • 229
  • Same principle applies -- convert the list/tree/whatever items into the abstract model index and then go back into the abstract model which is attached to the widget. – spraff Jul 18 '11 at 10:58
  • 1
    Cheers, the annswer was to do model->fileName(ui->fileList->selectionModel()->selectedIndexes().first()) – James Bennet Jul 18 '11 at 11:29