Search code examples
qtmodel-view-controllermodelqlistqfilesystemmodel

Qt MVC - Get filename when user clicks?


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.


Solution

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