QFileSystemModel 和 QFileSystemWatcher 从磁盘删除
我有一个 QTreeView,它是通过 QFileSystemModel 的重新实现来填充的。据我所知,QFileSystemModel 在 rootPath 上安装了 QFileSystemWatcher。我想做的是在 rootPath 上直接删除文件时在我的程序中发出通知,但我还没有找到任何信号或重新实现的函数来为我提供该信息。
我的应用程序通过 ftp 连接上传一些文件,当文件完全上传时,我将其从该位置删除,因此我希望在直接删除文件时(而不是通过删除方法或类似的方法)重新实现 QFileSystemModel 发出通知。
我希望你能帮助我。我在网上搜索了很多,但找不到任何东西。
干杯。
I have a QTreeView which is populated through a reimplementation of QFileSystemModel. As far as I know, QFileSystemModel installs a QFileSystemWatcher on the rootPath. What I'm trying to do is notify in my program when a file is being deleted directicly on the rootPath but i havent found any signal o reimplemented function which provides me that information.
My application upload some files thrugh an ftp connection and when the file is fully uploaded i remove it from the location, so i want a notification from the reimplementation of QFileSystemModel when the file is deleted directicly (not from the remove method or something similar).
I Hope you can help me. I have searched a lot on the web but I cant find anything.
Cheers.
您可以使用
FileSystemModel
的rowsAboutToBeRemoved< /code>
信号(继承自
QAbstractItemModel
)。每当从模型中删除一行时都会触发它。
parent
、start
和end
参数允许您获取文件名(在子项的第 0 列中)。示例代码:(
我认为使用 std::cout 并不是 Qt 的好习惯,这只是为了让您开始。)
来自 QAbstractItemModel 的其他
aboutToBe...
信号可用于其他文件系统上发生的事件。You can use the
FileSystemModel
'srowsAboutToBeRemoved
signal (inherited fromQAbstractItemModel
).It will be fired whenever a row is removed from the model. The
parent
,start
andend
parameters allow you to get to the filename (in column 0 of the children).Sample code:
(Using std::cout isn't good practice with Qt I think, this is just to get you started.)
The other
aboutToBe...
signals from QAbstractItemModel can be used for the other events that happen on the filesystem.