PDA

View Full Version : QFileSystemWatcher problem



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);


}

stampede
30th July 2014, 06:57
"watcher" goes out of scope when the constructor completes, allocate it on the heap or make it a class member.

YDYD
30th July 2014, 09:57
Hi stampede,

when i declared
QFileSystemWatcher *watcher=new QFileSystemWatcher;

it works,

but i declared in .h file "private",it is not working.

"The program has unexpectedly finished."

stampede
30th July 2014, 13:54
it is not working
It is impossible to help without seeing relevant code.