读书人

怎样C语言编程触发QFileSystemWatcher

发布时间: 2012-04-24 14:15:38 作者: rapoo

怎样C语言编程触发QFileSystemWatcher类发出fileChanged()信号
实现功能:当/home/ma/ma.txt文件被修改后,实时显示在TextEdit文本框里,用C语言对文件ma.txt修改(open()/write()等函数)则触发不了fileChanged(),但是用VIM打开时可以触发,我该怎么C编程来实现fileChanged()信号触发呢?

[解决办法]
另外,所有对文件的操作一定会发射信号的。也许你的代码有问题,我简单写了一个,测试没问题的。

C/C++ code
CMainForm::CMainForm(QWidget *parent)    : QWidget(parent),      ui(new Ui::CMainForm){    ui->setupUi(this);    watcher.addPath("/home/xiachm/123");    connect(&watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(fileChanged(const QString &)));}void CMainForm::fileChanged(const QString &path){    qDebug() << path;}void CMainForm::on_button_clicked(){    QFile file("/home/xiachm/123");    file.open(QIODevice::WriteOnly);    file.write("xiachm");    file.close();} 

读书人网 >QT开发

热点推荐