Solved Casts for events
-
Hello,
Is there a special method for downcastingQEvent
s to more concrete types? I was thinking something likeqobject_cast
andqgraphicsitem_cast
? Should I simply stick todynamic_cast
instead?Thanks!
-
Qt uses
reinterpret_cast
andstatic_cast
made safe by checkingQEvent::type
so I suppose that's the way to go -
@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
andQHoverEvent
. 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 likeqobject_cast
, there isn't.