c++ - 使用 Qt 挂载网络驱动器

标签 c++ qt qt4

我尝试使用 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/

相关文章:

C++ 编译器为 AVX SIMD 代码中从自身减去 +-Infinity 或 +-NaN 的恒定传播给出不同的 NaN 符号

qt - 带有 QSqlModel 的 QML 组合框

c++ - 如何将 Qt 信号/槽名称存储到数据结构中?

c++ - 如何区分存储在 QGraphicsScene.selectedItems() 上时继承 QGraphicsItems 的对象

c++ - 在 Windows 中使用 cpp 的窗口函数

c++ - 包含指数的嵌套循环的时间复杂度是多少?

c++ - Boost 将对象序列化为 json

c++ - 这个前向声明有什么问题

c++ - VS2010 中的 Qt - 无法使用设计器创建的对象

windows - 使用 CMake : Missing moc, uic、rcc 查找 Qt