Casts for events


  • Qt Champions 2017

    Hello,
    Is there a special method for downcasting QEvents to more concrete types? I was thinking something like qobject_cast and qgraphicsitem_cast? Should I simply stick to dynamic_cast instead?

    Thanks!


  • Qt Champions 2018

    Qt uses reinterpret_cast and static_cast made safe by checking QEvent::type so I suppose that's the way to go


  • Qt Champions 2017

    @VRonin said in Casts for events:

    Qt uses reinterpret_cast and static_cast made safe by checking QEvent::type so I suppose that's the way to go

    Yes, this is what I do usually. The point is there are multiple event types that map to the same class, for example QMouseEvent and QHoverEvent. Meaning you have to check all possible types (i.e. a big switch) before doing the cast. But fair enough, if there isn't anything like qobject_cast, there isn't.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.