PDA

View Full Version : subclassing QEvent to create custom events example



yapatel
1st April 2014, 22:50
I had a Qt3 app that used QEvents setData method and I am porting this to Qt4. I noticed there is not setData function anymore.

I read in the docs that you should subclass QEvent.

Does anyone have an example of how to subclass QEvent to make custom events and how to set the data for that custom event?

anda_skoa
2nd April 2014, 09:10
Just create a derived class like you would for any other C++ class.

Pass an event number as the type to the base class constructor, e.g. starting at QEvent::User + 1 or using QEvent::registerEventType() to generate one.

Since this is your class now, you can put any number of data members into it that you'd like.

Cheers,
_