QSocketNotifier and QFile::readAll()
QSocketNotifier and QFile::readAll()
目前在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的垃圾。
相关文章:
- readAll() 或 readAllStandardOutput() 在执行之前也返回一个空字符串
- QTcpSocket::readAll() is empty
- 调用readAll()后,不再无法从QIODevices检索数据.缓冲区已冲洗
- 来自qsocket的ReadyRead()信号的行为
- 来自 QSerialPort 的 readAll() 不包括上次发送的响应
- 当再次请求相同的url时,Qt QNetworkReply readAll返回空
- 使用 QProcess->setReadChannelMode(QProcess::MergedChannels) 并使用 QProcess->readall()
- QTCPSocket readAll()函数的奇怪行为
- AttachConsole and QProcess::readAll()
- QSocketNotifier and QFile::readAll()
- QtSerialPort:readAll不会产生所有数据,也没有新的readyRead信号
- 正在输出QProcess readAll对标签的响应