[Qt-interest] How to use QEvent::registerEventType properly

Girish Ramakrishnan girish at forwardbias.in
Wed Dec 15 20:01:53 CET 2010


Yes, casting it to QEvent::Type is fine (you can use static_cast too).

Girish

On Tue, Dec 14, 2010 at 8:09 PM, Brian McKinnon <bpmckinnon.qt at gmail.com> wrote:
> I'm building my own custom event and I want to just put this out there to
> see if anyone is offended by the way I use the registerEventType function
> (since I can't find any specific info on how to use it).  I think it make
> sense... but I've never casted a new value into a predefined enum... and I
> fear change.
>
> ShapeAnimationEvent.h:
>
> #ifndef SHAPE_ANIMATION_EVENT_H
> #define SHAPE_ANIMATION_EVENT_H
>
> #include <QEvent>
> #include <QVariant>
>
> class ShapeAnimationEvent : public QEvent
> {
> public:
>     static const QEvent::Type JUMP_TO_TIME;
>
>     ShapeAnimationEvent(QEvent::Type type, QVariant data);
>     QVariant data() const;
>
> private:
>     QVariant m_data;
>
> };
>
> #endif
>
> ShapeAnimationEvent.cpp:
>
> #include "ShapeAnimationEvent.h"
>
> const QEvent::Type ShapeAnimationEvent::JUMP_TO_TIME =
> (QEvent::Type)QEvent::registerEventType();
>
> ShapeAnimationEvent::ShapeAnimationEvent(QEvent::Type type, QVariant data) :
> QEvent(type), m_data(data)
> {
>
> }
>
> QVariant ShapeAnimationEvent::data() const
> {
>     return m_data;
> }
>
> Thanks,
> Brian!
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>



More information about the Qt-interest-old mailing list