Qt工作笔记-QFileSystemModel创建文件系统信息模型
生活随笔
收集整理的這篇文章主要介紹了
Qt工作笔记-QFileSystemModel创建文件系统信息模型
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
程序運(yùn)行界面如下:
總結(jié)下他的邏輯步驟:
1.實(shí)例化一個(gè)模型;
2.設(shè)置模型的根路徑(要監(jiān)視的路徑);
3.為視圖指定索引;
4.最后指定根索引;
代碼如下:
#include <QApplication> #include <QFileSystemModel> #include <QTreeView> #include <QListView> #include <QDir> #include <QDebug>int main(int argc, char *argv[]) {QApplication a(argc, argv);QFileSystemModel model;model.setRootPath("C:\\");QTreeView tree;tree.setModel(&model);tree.setRootIndex(model.index("C:\\"));tree.show();QFileSystemModel model2;model2.setRootPath(QDir::currentPath());QListView list;list.setModel(&model2);list.setRootIndex(model2.index(QDir::currentPath()));list.show();return a.exec(); }總結(jié)
以上是生活随笔為你收集整理的Qt工作笔记-QFileSystemModel创建文件系统信息模型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工作笔记-QGraphics框架中,
- 下一篇: 节约内存编程方式操作系统(全概念)