【问题标题】:How to obtain the changed file names from the QFileSystemWatcher `directoryChanged` event如何从 QFileSystemWatcher `directoryChanged` 事件中获取更改的文件名
【发布时间】:2014-04-20 07:10:03
【问题描述】:

如何从 QFileSystemWatcher directoryChanged 事件中获取更改的文件名?

【问题讨论】:

    标签: c++ qt qtcore qt-signals qfilesystemwatcher


    【解决方案1】:

    如果您对文件名更感兴趣,您需要将您的插槽连接到fileChanged() 信号而不是directoryChanged()

    connect(&myFileSystemWatcher, SIGNAL(fileChanged(const QString&)), SLOT(handleFileChanged(const QString&)));
    

    然后,您可以根据需要使用 slot 参数。在这里,我只是将它打印到标准输出:

    void handleFileChanged(const QString &path)
    {
        qDebug() << path;
    }
    

    请参阅文档了解更多详情:

    void QFileSystemWatcher::fileChanged(const QString & path) [signal]

    当指定路径的文件被修改、重命名或从磁盘中删除时发出此信号。

    不确定你对 Qt 信号/槽系统了解多少,但如果还不够,也请过一遍:

    Qt Signals & Slots

    【讨论】:

    • 至于添加、修改和删除的区别,this post可能对Robin的读者有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    相关资源
    最近更新 更多