Reputation: 71
i try to mount a network drives(CIFS) in Linux with Qt. But it doesnt work. Is there also another solution, without QProcess?
QProcess connectSamba;
QString terminalCommand;
terminalCommand = "mount -t cifs //" + ip + "/folder/ " + mountpath;
connectSamba.start(terminalCommand);
Upvotes: 1
Views: 2158
Reputation: 27611
Rather wondering if there's another solution, I think you should examine and understand why QProcess doesn't work for you.
Calling QProcess::start in this way will take the first token (mount) as the command and pass each of the following items, separated by a space, as arguments. Therefore, tokens such as "//" and "/folder/" are not valid arguments for the mount command.
You can use QProcess by doing something like this: -
QProcess connectSamba;
QString mountPath = "//" + ip + "/folder/ " + mountpath;
QString terminalArgs = QString("-c \"mount -t cifs %1\"").arg(mountPath);
connectSamba.start("/bin/bash", terminalArgs);
connectSamba.waitForFinished();
Note that the terminal arguments are surrounded by quotes to ensure that only one argument is passed and we're calling the bash interpreter with the -c argument, which takes commands from the proceeding string.
Upvotes: 3