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(model.data(tree.currentIndex(), 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 ":http://doc.qt.nokia.com/4.7-snapshot/qabstractitemmodel.html#data Do you get invalid QVariant in your case?