我使用QFile打开一个每秒钟接收数据的Linux FIFO。
fp = new QFile(DCB_DATA_INPUT);
if(fp->open(QIODevice::ReadOnly| QIODevice::Text))
{
log_d(1,TAG,"Open agiin success");
s_notifier = new QSocketNotifier(fp->handle(), QSocketNotifier::Read, this);
s_notifier->setEnabled(true);
connect(s_notifier, SIGNAL(activated(int)), this, SLOT(notifier_process(int)));
return true;
}
notifier_process(int) {
qint64 avai = fp->bytesAvailable();
log_d(1,TAG,QString("%1").arg(avai));...}
答案 0 :(得分:1)
由于存在open bug report about this issue,我建议使用标准Linux API:
void notifier_process(int)
{
int bytesAvailable;
ioctl(fp->handle(), FIONREAD, &bytesAvailable);
char buffer[1024] = {0};
read(fp->handle(),&buffer,bytesAvailable);
qDebug() << buffer;
}