YDYD
30th July 2014, 02:13
Hi all,
I am using a QFileSystemWatcher to keep an eye on a Picture on RAM disk.
When the picture is replace by another, which mean it is "modified".
and i would like to emit a signal and get the image to display on a QLabel.
It works when i use QTimer to replace the QFileSystemWatcher.
It seems QFileSystemWatcher is not emitting any signal.
my code ask following:
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
/* timer = new QTimer(this);
timer->start(100);*/
QFileSystemWatcher watcher;
watcher.addPath("/mnt/rd/frame.jpg");
hsvSaveConnect();
checkBox();
connect(ui->save,SIGNAL(clicked()),this,SLOT(saveValueToSD())) ;
connect(ui->load,SIGNAL(clicked()),this,SLOT(loadInitValue())) ;
connect(&watcher,SIGNAL(fileChanged(const QString &)),this,SLOT(loadImage()));
connect(&watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(loadImage()));
qDebug() << watcher.files() << watcher.directories();
}
void Dialog::loadImage()
{
qDebug() << "img loaded";
QPixmap original("/mnt/rd/frame.jpg");
if(original.isNull())
{
qDebug()<<"Failed to load image.";
}
ui->original->setPixmap(original);
}
I am using a QFileSystemWatcher to keep an eye on a Picture on RAM disk.
When the picture is replace by another, which mean it is "modified".
and i would like to emit a signal and get the image to display on a QLabel.
It works when i use QTimer to replace the QFileSystemWatcher.
It seems QFileSystemWatcher is not emitting any signal.
my code ask following:
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
/* timer = new QTimer(this);
timer->start(100);*/
QFileSystemWatcher watcher;
watcher.addPath("/mnt/rd/frame.jpg");
hsvSaveConnect();
checkBox();
connect(ui->save,SIGNAL(clicked()),this,SLOT(saveValueToSD())) ;
connect(ui->load,SIGNAL(clicked()),this,SLOT(loadInitValue())) ;
connect(&watcher,SIGNAL(fileChanged(const QString &)),this,SLOT(loadImage()));
connect(&watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(loadImage()));
qDebug() << watcher.files() << watcher.directories();
}
void Dialog::loadImage()
{
qDebug() << "img loaded";
QPixmap original("/mnt/rd/frame.jpg");
if(original.isNull())
{
qDebug()<<"Failed to load image.";
}
ui->original->setPixmap(original);
}