大家好,我碰到了个问题,困扰了我好几天,不知道怎么解决,大侠们能否给看一下
我以阻塞的方式读取IO按键状态(按键驱动中是以中断的方式来记录状态的)然后再显示到界面上,所以在程序中用了select系统调用,读取IO状态没有问题而且数据也是正确的,但在显示数据到界面的时候,程序却没有任何响应(此时点程序的其它部分也没有任何响应),但程序确实没有死,源代码如下:
#include "frmmain.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qstring.h>
void OpenDevice()
{
int button_fd=open("/dev/buttons",0);
if(button_fd<0)
{
perror("open device button");
exit(1);
}
while (1)
{
fd_set rds;
int ret;
FD_ZERO(&rds);
FD_SET(button_fd,&rds);
printf("waiting for keypress!\n");
ret=select(button_fd+1,&rds,NULL,NULL,NULL);
if(ret<0)
{
perror("select");
exit(1);
}
else if(ret==0)
{
printf("Time out\n");
}
else if(FD_ISSET(button_fd,&rds))
{
int readret=read(button_fd,key_values,sizeof(key_values));
if(readret!=sizeof(key_values))
{
if(errno!=EAGAIN)
perror("read button");
continue;
}
else
{
//showData();
this->setCaption("llllllllllllllllllllllllllllppppp"); //没有正常显示,而且程序界面没有任何响应
printf("key pressed!\n"); //可以正常显示
}
}
}
close(button_fd);
}