[SOLVED] How to detect USB devices
-
wrote on 10 Nov 2015, 09:04 last edited by alsa
My aim is to save a txt file from my Qt app to an external device (SD card, USB pendrive...). The app is created for an embedded system.
My problem is: how detect which USB device is connected when I inserted a USB pen, in such a way that I can save my file in it?
Which is the best method using Qt? -
wrote on 10 Nov 2015, 09:07 last edited by
Usually, mounting storage devices is handled by the OS.
What is the target OS for which you are developing? -
wrote on 10 Nov 2015, 09:13 last edited by alsa 11 Oct 2015, 09:14
I'm developing on Ubuntu 14.04 for a Single Board Computer Variscite (its OS is Linux-embedded)
-
wrote on 10 Nov 2015, 09:20 last edited by
If your goal is only to store data, use this command QFileDialog::getSaveFileName(); If your goal is only to store data, use this command. Do not forget the file header #include <QFileDialog>
-
I'm developing on Ubuntu 14.04 for a Single Board Computer Variscite (its OS is Linux-embedded)
wrote on 10 Nov 2015, 09:25 last edited by McLion 11 Oct 2015, 09:26@alsa
Does your eLinux mount newly attached storage devices automatically to a mount point or does it only create a device file?I had the same task on eLinux as well. My system did create the device file only (busybox with mdev). I used a QFileSystemWatcher to detect changes in /dev, ie. attached sdan and acted on that with mounting/unmounting the device.
-
wrote on 10 Nov 2015, 11:55 last edited by
It only creates a device file
-
wrote on 10 Nov 2015, 12:03 last edited by
@alsa
Then look into QFileSystemWatcher. -
wrote on 10 Nov 2015, 16:04 last edited by
To start:
// prepare FS watcher to detect added USB memory FSwatcher = new QFileSystemWatcher(this); FSwatcher->addPath("/dev"); connect(FSwatcher, SIGNAL(directoryChanged(QString)), this, SLOT(showModifiedDirectory(QString)));
HTH
McL -
wrote on 23 Dec 2016, 06:32 last edited byThis post is deleted!
-
To start:
// prepare FS watcher to detect added USB memory FSwatcher = new QFileSystemWatcher(this); FSwatcher->addPath("/dev"); connect(FSwatcher, SIGNAL(directoryChanged(QString)), this, SLOT(showModifiedDirectory(QString)));
HTH
McL