0

I'd like to detect when a SDCARD or USB is inserted in my QT based linux embedded System. I made the following, but I think something is missing:

    FSwatcher = new QFileSystemWatcher(this);
    FSwatcher->addPath("/run/media");
    connect(FSwatcher, SIGNAL(directoryChanged(QString)), this,SLOT(showModifiedDirectory(QString)));
}
void ts400::showModifiedDirectory(QString)
{
qDebug() << "Detected++++++++++++++++++++++++++++++++";
}

I don't understand why the connector doens't function (no call to my Slot). Is there someone who can give some instruction about? Thanks

LittleSaints
  • 391
  • 1
  • 6
  • 19
  • I can't see anything wrong with you code -- have you verified that the device does indeed show up in /run/media? – mzimmers Apr 28 '22 at 14:41
  • 1
    I haven't checked but I suspect `QFileSystemWatcher` on linux makes use of [`inotify`](https://man7.org/linux/man-pages/man7/inotify.7.html). Unfortunately certain parts of the file system (or, perhaps more correctly, their 'drivers') don't support the `inotify` protocol. That may well be the case for `/run/media` in which case you won't receive any signals. – G.M. Apr 28 '22 at 14:55
  • You can try a different approach - get a listing of `run/media` directory periodically (e.g. every second) and compare with the previous values if the list changed. This should be fairly simple. – HiFile.app - best file manager Apr 28 '22 at 20:55

0 Answers0