PDA

View Full Version : Qfilesystemwatcher filechanged() signal not triggering



nagendrababu
24th June 2018, 06:17
Hi All,
I am trying to use qfilesystemwatcher on a touch input file to detect touch idleness for a specific amount of time, And turn Display back light off/on accordingly. But I don't see the signal being triggered, when the file changed. The touch file I am monitoring is "/dev/input/event0" which is event file assocaited with my touch driver. When I check using cat command I could see this file being changed on each touch I do, But not working in my code using qfilesystemwatcher. Can you please look at my code and see, If I am missing anything?



QFileSystemWatcher *touchFileWatcher;
QStringList *watchPaths = new QStringList(Inputfile);
touchFileWatcher = new QFileSystemWatcher(*watchPaths,parent);
qDebug() << "touchFileWatcher Files: " << touchFileWatcher->files();
connect(touchFileWatcher,SIGNAL(fileChanged(const QString &)),this,SLOT(touchFileChanged(const QString &)));

void Hardware::touchFileChanged(const QString &path)
{
qDebug() << "File changed" << path;
}

Uwe Yashwanth
25th June 2018, 05:11
Try giving only QString as an argument and also for passing any parameters to a slot you need to use QSignalMapper.
Here : QSignalMapper


QSignalMapper* map1= new QSignalMapper (this) ;
connect (any_action, SIGNAL(triggered()), map1, SLOT(map())) ;
map1-> setMapping (any_action, 1) ;//one is argument being passed
connect (map1, SIGNAL(mapped(int)), this, SLOT(onStepIncreased(int))) ;

nagendrababu
25th June 2018, 07:56
Hi Yashwanth,
I tried both signal mapper method as well as giving only Qstring as argument. But None of these options helped, I couldn't see the event being triggered.

Any More help?

Thanks,
Nagendra.

d_stranz
25th June 2018, 18:14
A device driver entry in the linux file system is not like an ordinary file, so it is possible that QFileSystemWatcher does not work for these. Try an experiment - have it look at an ordinary text file, edit the file, save it, and see if you get a signal.

It's also possible that Qt's input handlers for keyboard, mouse, and touch are already handling this, so QFileSystemWatcher is ignoring the file. Can't you use a handler for QTouchEvent to accomplish what you want instead of trying to watch the file?

nagendrababu
3rd July 2018, 00:15
Hi @d_stranz,
Thanks for your reply. Yes you are correct. QFileSystemWatcher isn't working for driver entry file. On normal text file it's working fine. I tried using QTouchInput, But it didn't work as expected.
So to solve this, I did override notify(QObject *sender,QEvent *event) method of QApplication and able to put this function as entry for all inputs. Once I do the processing, I am forwarding it to corresponding widget.

Thanks,
Nagendra