主题 : 在QWidget的子类中自定义事件处理函数 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 15570
精华: 0
发帖: 28
金钱: 140 两
威望: 28 点
综合积分: 56 分
注册时间: 2010-03-07
最后登录: 2010-06-28
楼主  发表于: 2010-04-06 23:06

 在QWidget的子类中自定义事件处理函数


在程序中直接重新定义QWidget类的customEvent函数编译通过,如下定义,
void QWidget::customEvent(QCustomEvent *e)   //用户自定义事件处理函数
{
             if (e->type()==60000)  
         {  
                    UserEvent *re = (UserEvent *) e;      
                    newstring = re->str();
         }
}
但是没有事件处理。

在QWidget类的子类ChildWidget中定义customEvent函数如:
void ChildWidget::customEvent(QCustomEvent *e)   //用户自定义事件处理函数
{
             if (e->type()==60000)  
         {  
                    UserEvent *re = (UserEvent *) e;      
                    newstring = re->str();
         }
}
会提示ChildWidget类中没有customEvent函数,因为ChildWidget子类已经继承了QWidget类 为什么不能在子类中重定义customEvent函数呢?