PDA

View Full Version : Connect to network drive



bandito
8th April 2020, 14:48
So I am attempting to build an app that will backup my files to a network drive.

Presently my network drive is a usb stick connected to my router. At the moment I can't figure out ho to connect to the network drive using Qt. I have fiddled with QDir and QDesktopServices but I cannot get either to list the files on the network drive. Could someone point me in the right direction? Thanks.

d_stranz
8th April 2020, 16:07
If the drive is not mounted at the OS level (ie. using linux mount or making a connection as a Windows network drive) so the OS filesystem sees it then Qt can't see it either, since Qt's file services are layered on top of the underlying file system.

You can possibly use QProcess to mount the drive, at which point you can access it, as explained in this stackoverflow post (https://stackoverflow.com/questions/27822854/mount-network-drives-with-qt) based on linux. I imagine there is some equivalent in Windows.

bandito
8th April 2020, 16:45
If the drive is not mounted at the OS level (ie. using linux mount or making a connection as a Windows network drive) so the OS filesystem sees it then Qt can't see it either, since Qt's file services are layered on top of the underlying file system.

You can possibly use QProcess to mount the drive, at which point you can access it, as explained in this stackoverflow post (https://stackoverflow.com/questions/27822854/mount-network-drives-with-qt) based on linux. I imagine there is some equivalent in Windows.

I am actually using Linux, Ubuntu specifically and I have the drive mounted already.

d_stranz
9th April 2020, 00:15
I am actually using Linux, Ubuntu specifically and I have the drive mounted already.

Does the account from which you are running the Qt app have the same access rights as the directory at the mount point? If so, I am surprised that the Qt program can't see it. Perhaps one of the linux gurus here can add more.

bandito
10th April 2020, 14:42
So I finally figured out to connect to a network drive. If I put /run/user/1000/gvfs/smb-share:server=192.168.0.1,share=volume(sda1) as the path in QDirIterator it works fine. Had to use QFileDialog to fine the path however. Using "//192.168.0.1/volume(sda1)" as a path doesn't work.