Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Casts for events
Forum Updated to NodeBB v4.3 + New Features

Casts for events

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 971 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #1

    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!

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      kshegunovK 1 Reply Last reply
      5
      • VRoninV VRonin

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

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        @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.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved