tableview 怕是无法展开文件系统吧;一般使用的数QTreeView;
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
ui->treeView->setModel(model);
void Widget::on_treeView_clicked(const QModelIndex &index)
{
QFileSystemModel * mode = qobject_cast<QFileSystemModel*>(ui->treeView->model());
if(mode->isDir(index)){
QString path = mode->filePath(index);
qDebug()<<"路径:"<<path;
QDir dir(path);
auto ret = dir.entryList();
qDebug()<<ret.size();
}
}
直接调用rowCount()没有参数吗,那不就是返回root的rowCount,如果要某个文件夹下面的应该把对应的index传进去吧