I have created a custom event in my Qt application by subclassing QEvent.
class MyEvent : public QEvent
{
public:
MyEvent() : QEvent((QEvent::Type)20
For convenience, you can use the QEvent::registerEventType() static function to register and reserve a custom event type for your application. Doing so will allow you to avoid accidentally re-using a custom event type already in use elsewhere in your application.
Example:
class QCustomEvent : public QEvent
{
public:
QCustomEvent() : QEvent(QCustomEvent::type())
{}
virtual ~QCustomEvent()
{}
static QEvent::Type type()
{
if (customEventType == QEvent::None)
{
int generatedType = QEvent::registerEventType()
customEventType = static_cast(generatedType);
}
return customEventType;
}
private:
static QEvent::Type customEventType;
};
QEvent::Type QCustomEvent::customEventType = QEvent::None;