QSocketNotifier and QFile::readAll()

QSocketNotifier and QFile::readAll()

本文关键字:readAll QSocketNotifier QFile and      更新时间:2023-10-16

目前在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"可以修改为在下降边、上升边、两个边或没有边时引发中断,这意味着应该只在这些边上引发中断。

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