QSocketNotifier和QFile :: readAll() [英] QSocketNotifier and QFile::readAll()

查看:203
本文介绍了QSocketNotifier和QFile :: readAll()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在使用SBC(Olimex A20)的GPIO,QSocketNotifier出现了问题.在我的GPIO上,我正在使用具有中断功能的引脚(对于那些想了解更多的人:

Currently working on the GPIOs of a SBC (Olimex A20), I have a problem with QSocketNotifier. On my GPIOs, I'm using a pin with interruption abilities (For those who want to know more : https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals ) and a QSocketNotifier to monitor the changes.

这是我上课的时间:

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 ),但是问题变了,所以我在这里再次询问.

I already asked a question (here : https://stackoverflow.com/questions/23955609/qtimer-and-qsocketnotifier) but the problem changed, so I ask again here.

为什么QSocketNotifier持续发出信号?在GPIO的目录中,可以修改文件"edge",以在下降沿,上升沿,无边沿或无边沿时引发中断,这意味着仅应在该边缘处引发中断.

Why is QSocketNotifier continuously emitting a signal ? In the directory of the GPIO, the file "edge" can be modified for raise an interruption on falling, rising, both or no edge, which means an interruption should be raised only on this edges.

推荐答案

好,我的解决方法是:QSocketNotifier不断发出信号,直到您在文件上使用"readAll()"功能为止.因此需要尽快调用readAll()来停止QSocketNotifier的垃圾邮件.

Ok, I have my solution : The QSocketNotifier emits continually the signal until you use the "readAll()" function on the file. So need to call as soon as possible readAll() to stop the spam of the QSocketNotifier.

这篇关于QSocketNotifier和QFile :: readAll()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆