Qt: Defining a custom event type

后端 未结 3 1198
粉色の甜心
粉色の甜心 2020-12-29 07:53

I have created a custom event in my Qt application by subclassing QEvent.

class MyEvent : public QEvent
{
  public:
    MyEvent() : QEvent((QEvent::Type)20         


        
3条回答
  •  自闭症患者
    2020-12-29 08:06

    If the event-type identifies your specific class, i'd put it there:

    class MyEvent : public QEvent {
    public:
        static const QEvent::Type myType = static_cast(2000);
        // ...
    };
    
    // usage:
    if(evt->type() == MyEvent::myType) {
        // ...
    }
    

提交回复
热议问题