Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Unmounting USB device through Qt
Is there any way to unmount a USB device safely through Qt? Something like this:
I have searched in Forums but many of them are not that sure of the answer or say that it is not possible. Do I have to use QProcess? QtSystems?
Basically the user will click a button which contains the "Eject" icon and it will unmount the USB (flash drive) that it is currently connected. Then the user will be able to take out the USB from the port.
Maybe qtwinextras provides something.
Else you will need to use native API.
If you need it only for windows?
Maybe just use a command line tool?
And call it from your program.
Alternative, you can have a look here for inspiration
@mrjj it is going to be on Linux. So for Linux, when I am running my Qt application, does the Terminal need to pop up in order for the user to enter it to eject the USB? or can it be done behind the scenes. The reason is because the Qt application is going to be run on a touchscreen and the just pressing on the QPushButton will make it easier for the user to eject. The user will not have Admin privileges.
Are USB Devices automatically mounted when they are plugged in?
@the_ yes they are. By USB i mainly mean like a flash drive which they are mainly in /media/user/
you can try to call
@the_ Is pmount from a library? I can't seem to find one for it.
pmount is a shell command.
marlenet15 last edited by marlenet15
@the_ So does the Qt application need to open the Terminal window in order for "pmount /media/path/to/flashdrive" to work? Or can I still send the command without opening the Terminal window. In other words, I don't want the user to mess with the Terminal. I just would like for them to press the button and their flash drive should unmount.
I tried using the following but it doesn't unmount:
QStringList parameters; parameters<<"/media/user/nameOfFlashdrive/"; QProcess ps; ps.start("pumount", parameters); ps.waitForFinished(-1);
@the_ Ok I had to install "pmount" and It works but not really. The USB folder disappears but it is still under media device on the File Manager window. Do you happen to know if "pumount" ejects the usb safely?
pmount is a wrapper for the normal mount command
allowing normal user (non root) to
As far as I know, the pumount is used for unmounting devices?
as least here on ubuntu it seems to work pretty safe.
@mrjj so by just running "pumount" it will unmount the usb safely?
yes it should.
you can read about it here
it seems to expect the device to be mounted under /media.