Qt工作笔记-QFileSystemModel创建文件系统信息模型
生活随笔
收集整理的這篇文章主要介紹了
Qt工作笔记-QFileSystemModel创建文件系统信息模型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序運行界面如下:
總結下他的邏輯步驟:
1.實例化一個模型;
2.設置模型的根路徑(要監視的路徑);
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(); }總結
以上是生活随笔為你收集整理的Qt工作笔记-QFileSystemModel创建文件系统信息模型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工作笔记-QGraphics框架中,
- 下一篇: C++ opengl 学习笔记-在Ope