Hi All!
First post here and I am certainly a QT newbie.
In my quest to learn the QT5 API & Widgets, I thought I would make a simple file explorer to allow a user to navigate a directory structure. I was pleasantly amazed at how quickly I could get this working in QT with the following code:
Qt Code:
void MainWindow::initTreeView() { dirModel = new QFileSystemModel(this); dirModel->setRootPath(""); ui->treeView->setModel(dirModel); }To copy to clipboard, switch view to plain text mode
This works great at first, however as I navigate the ui->treeView I observed the following:
* Expanding a node with a large number of subdirectories (say over 10,000) causes the UI to become unresponsive for ~8-10 seconds. On my system (Windows 7), for instance C:\Windows\winsxs can easily have 10k+ subdirectories. According to the official QT documentation:
* After expanding a large directory/node then collapsing this node as noted above, expanding other nodes (even nodes with only a few directories) becomes sluggish with a 2-3 second delay before the UI becomes responsive again.Unlike QDirModel(obsolete), QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls to rowCount() will return 0 until the model populates a directory.
I've also noticed that Windows Explorer can expand and navigate these structures instantly (with no detectable delay) so I'm most likely not doing something right here. Am I missing some optimization setting I should be turning on or am I expecting too much from QFileSystemModel?
Thanks in advance for any help!
- Zep
Bookmarks