Important: Please read the Qt Code of Conduct -

Selection in a QFileSystemModel and QTreeView

  • I've created a QTreeView with a QFileSystemModel for the user to select a file to be used by the rest of the program. I'm having trouble obtaining the selected file as a QString. Currently I have this function:

    @void MyWidget::setFileName()
    file = "";
    file.append(, Qt::DisplayRole).toString());
    Where model is the QFileSystemModel and tree is the QTreeView

  • bq. Note: If you do not have a value to return, return an invalid QVariant instead of returning 0.

    This note is taken from "the official documentation of QAbstractItemModel which is inherited by QFileSystemModel ": Do you get invalid QVariant in your case?

Log in to reply