QFileSystemModel and QTreeView

青春壹個敷衍的年華 提交于 2019-12-13 02:46:39

问题


I show a QFileSystemModel through a QTreeView.

Whenever the user clicks on a directory (expanded or not expanded) I want to get a list of the files inside this directory.

void MyModel::selectionChanged(const QItemSelection& selected,const QItemSelection& deselected) {
    for (auto const & it : selected.indexes()) {
        for (int i=0;i<rowCount(it);i++) {
            auto child = it.child(i, it.column());
            qDebug() << fileName(child);
        }
    }
}

The problem with the above code is that this only seems to work once that particular directory has been expanded. As long as the directory has never been expanded (since program start) rowCount is 0.

How can I force the model to populate the children of the given model index? Without necessarily showing the children in the view? One level of children indexes would be enough in this case.

来源:https://stackoverflow.com/questions/48048644/qfilesystemmodel-and-qtreeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!