linux - system() 调用的 WiringPi gpio 必须使用另一个进程?

标签 linux qt raspberry-pi2 wiringpi

根据 this ,我在我的程序中使用 system() ( QProcess ) 函数来调用 gpio 程序。

它有效。但我注意到我需要运行我的应用程序两次,实际上它只在第二次运行。似乎对 gpio 的调用必须在另一个进程中完成,如所指出的那样here .

这个问题应该用QProcess::setupChildProcess()来解决吗? ?

我扩展了 QProcess 覆盖 setupChildProcess,然后在我的应用程序的构造函数中实例化了 SandboxProcess。不幸的是,这没有用。

class SandboxProcess : public QProcess
{
 protected:
     void setupChildProcess();
};
void SandboxProcess::setupChildProcess()
{
    QString program = "/usr/local/bin/gpio";
    QStringList arguments;
    arguments << "export" << QString::number(4) << "out";
    start(program, arguments);
}

最佳答案

我猜 QProcess::setupChildProcess() 没有帮助,因为它自己的进程在主应用进程之后启动。所以主应用程序仍然像导出命令没有执行一样。

此时我看到两个选项:

  1. 创建一个 ManagerApp,它调用 gpio(进行导出),然后调用(另一个)MyApp,它将实际访问导出设备。
  2. 直接使用 gpio 应用程序并使用 QProcess 通过 signal/slot 收听他们的 stdout

关于linux - system() 调用的 WiringPi gpio 必须使用另一个进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33835778/

相关文章:

c++ - QT SDL 未被识别(列出了 Qmake 文件。我做错了吗?)

java - Intellij IDEA、java和远程开发

raspberry-pi2 - 无法 ssh 到 Raspberry pi PuTTy,显示 "unable to open connection to raspberrypi.local Host does not exist!"错误

c++ - dbus-send与QDBusAbstractInterface的对应关系

swift - (交叉)为 Raspberry PI 编译 Swift

c - 你怎么能 "avoid"SIGSEGV?

linux - ubuntu 13.04 服务器上的 locale-gen 不起作用

linux - 使用最后一个字段对文本文件进行排序

linux - 在 Linux 上访问 x86-64 架构上的堆栈帧

Qt QMdiArea 背景上的图像