QT: QFileSystemModel _q_fileSystemChanged slot is executed on the UI thread which contradicts documentation
My UI is using QTreeView with QFileSystemModel to be able to select folders and files. The documentation for QFileSystemModel says that file structure update is done on a seperate thread which would mean the UI would not be blocked. However, this is not the case for me and I can't figure out the discreptency and how other people are not running into this issue. After debugging, I noticed that QFileSystemModel _q_fileSystemChanged slot which takes most of the time is still executed on the main UI thread which makes sense. The Questiong is how does the documentation claim than that it will not block the UI. Is there a solution? Am I misunderstanding something?
To repro - Create 开发者_运维问答a QTreeView with QFileSystemDataModel - Set root path to "" or "/" - Set breakpoint in QFileSystemModel _q_fileSystemChanged slot - Expand one of the drives after app loads
Problem: - The slot is called on the UI thread thus blocking the app until it finishes.
There are ways to make the file parser faster, but it I really need to execute on a seperate thread and notify when the data is populated and ready for QTreeView.
Thanks, Innokenty
I think the reason for this could be the icons. Within the _q_fileSystemChanged()
slot fileInfoGatherer.getInfo()
gets called which - among other things - resolves the icons for the paths. In it's current design QFileIconProvider
uses QIcon
to represent icons and QIcon
can only be used in the UI thread. QImage
seems to be the only class allowed to use in other threads, but I think it may be to expensive to use QImage
in the background thread and convert it to an QIcon
in the UI thread.
So it is possible that the platform implementation of QFileIconProvider
is slow on network paths under some circumstances and therefore slows down the UI main thread.
I don't know if this is the source of your problem, but at least this should be the reason why _q_fileSystemChanged()
is called within the UI thread.
精彩评论