【问题标题】:QSocketNotifier and QFile::readAll()QSocketNotifier 和 QFile::readAll()
【发布时间】:2014-06-02 07:37:03
【问题描述】:

目前正在处理 SBC (Olimex A20) 的 GPIO,我遇到了 QSocketNotifier 的问题。在我的 GPIO 上,我正在使用具有中断功能的引脚(对于那些想了解更多信息的人:https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals ) 和一个 QSocketNotifier 来监控变化。

这是我的打扰课:

OLinuXinoGPIOEdge::OLinuXinoGPIOEdge(int num)
    : m_gpioNumber(num), m_value(false), m_direction(IN)
{
    this->exportGPIO(); // equivalent to 'echo num > export'
    this->setDirection(IN); // for security
    m_fileValue.setFileName("/sys/class/gpio/gpio20_pi11"); // the path of the pin
    this->setEdge(BOTH); // edge's detection (both/falling/rising/none)
    m_timer = new QTimer();
    m_timer->setInterval(10);
    m_timer->setSingleShot(true);
    m_fileValue.open(QFile::ReadOnly);
    m_fileNotifier = new QSocketNotifier(m_fileValue.handle(), QSocketNotifier::Exception); // Actually, emits the signal whenever an interruption is raised or not
    connect(m_fileNotifier, SIGNAL(activated(int)), m_timer, SLOT(start()));
    connect(m_timer, SIGNAL(timeout()), this, SLOT(changeNotifier()));
}

我已经问过一个问题(这里:https://stackoverflow.com/questions/23955609/qtimer-and-qsocketnotifier)但是问题变了,所以我在这里再问一次。

为什么 QSocketNotifier 不断发出信号?在GPIO目录下,文件“edge”可以修改为在下降沿、上升沿、双沿或无沿时引发中断,即只在该沿引发中断。

【问题讨论】:

    标签: c++ linux qt debian qfile


    【解决方案1】:

    好的,我有我的解决方案:QSocketNotifier 不断地发出信号,直到您对文件使用“readAll()”函数。所以需要尽快调用readAll()来阻止QSocketNotifier的垃圾邮件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2020-03-06
      相关资源
      最近更新 更多