gpt4 book ai didi

c++ - QSocketNotifier 和 QFile::readAll()

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:09 25 4
gpt4 key购买 nike

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

这是我的打扰类(class):

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”以在下降沿、上升沿、两个边沿或无边沿产生中断,这意味着只应在该边沿产生中断。

最佳答案

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

关于c++ - QSocketNotifier 和 QFile::readAll(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23989477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com