我尝试使用 Qt 在 Linux 中安装网络驱动器 (CIFS)。但它不起作用。还有没有 QProcess 的另一种解决方案吗?
QProcess connectSamba;
QString terminalCommand;
terminalCommand = "mount -t cifs //" + ip + "/folder/ " + mountpath;
connectSamba.start(terminalCommand);
最佳答案
想知道是否有其他解决方案,我认为您应该检查并理解为什么 QProcess 不适合您。
调用 QProcess::start以这种方式将第一个 token (mount)作为命令并将以下各项作为参数传递,以空格分隔。因此,“//”和“/folder/”等标记不是挂载命令的有效参数。
您可以通过执行以下操作来使用 QProcess:-
QProcess connectSamba;
QString mountPath = "//" + ip + "/folder/ " + mountpath;
QString terminalArgs = QString("-c \"mount -t cifs %1\"").arg(mountPath);
connectSamba.start("/bin/bash", terminalArgs);
connectSamba.waitForFinished();
请注意,终端参数用引号括起来,以确保只传递一个参数,并且我们使用 -c 参数调用 bash 解释器,它从后续字符串中获取命令。
关于c++ - 使用 Qt 挂载网络驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27822854/