QSocketNotifier and QFile::readAll()

十年热恋 提交于 2019-12-25 03:15:26

问题


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.

That's my class for interruptions :

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()));
}

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/23989477/qsocketnotifier-and-qfilereadall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!