首页| 论坛| 消息

标题:linux底层signal如何链接到qtevent
作者:povoss
日期:2014-03-28 12:29
内容:

qtearm-4.8.0中,底层驱动can驱动已经实现,并且该驱动使用了异步通知,linux应用测试程序可以通过 signal(SIGIO,数据读取函数);调用数据读取函数,
但是在qte中如何实现呢?如下代码:
void MainWindow::on_btn_start_clicked()
{
QString str,temp;
int oflags;
unsigned int canid[6]={0x00000181,0x00000182,0x00000183,0x00000184,0x00000185,0x00000186};
fd = open("/dev/mcp2515",O_RDWR);//|O_NONBLOCK);//s=socket(PF_CAN, SOCK_RAW, CAN_RAW);
if(fdrecEdit->setText(str);
}
else
{
str.sprintf("open mcp2515 success,return val=%d,fd=%d\n",ret,fd);
ui->recEdit->setText(str);
}
signal(SIGIO,PostoQT);
fcntl(fd,F_SETOWN,getpid());
oflags=fcntl(fd,F_GETFL);
fcntl(fd,F_SETFL,oflags|FASYNC);
//ptimer->start(100);
}
PostoQT如果是MainWindow的成员函数,那么因为不是静态的编译报错。。。。
如果改静态。。。。。省略n字。。。
求解,如何链接事件响应。


#1 [povoss 03-28 16:35]

#2 [povoss 03-31 10:40]
好烂的论坛
#3 [yuxue 04-06 02:55]
看下qt 源码 有个qtmouselinuxinput 触摸或鼠标看他是怎么做的
#4 [povoss 04-10 16:06]
还得靠自己。
1.定义全局指针pmainwindow,定义事件值:
MainWindow *pmainWindow;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//QWSServer::setCursorVisible(false);
MainWindow mainWindow;
pmainWindow=&mainWindow;
。。。
mainwindow.h中增加
extern MainWindow* pmainWindow;
#define myeid (QEvent::Type)1000
void PostoQT(int num);
2.关联signal(SIGIO,PostoQT):
void PostoQT(int num)
{
//QMessageBox msg;
//msg.setText("handle.\n");
//msg.exec();
printf("i have received the sig=%d!\n",num);
//QApplication::postEvent(pmainWindow,new myevent);
QApplication::postEvent(pmainWindow,new QEvent(myeid));
}
3.重载customEvent函数
void MainWindow::customEvent( QEvent *e )
{
printf("e->type()=%d.\n",e->type());//for test
if ( e->type() == myeid) {// It must be myEvent
canrec();
}
}
canrec()中做接收处理。

回复 发表
主题 版块