QSocketNotifier and QFile::readAll()

2019-09-17 13:41发布

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条回答
我只想做你的唯一
2楼-- · 2019-09-17 14:13

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.

查看更多
登录 后发表回答