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. Custom QEvent question

Custom QEvent question

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 496 Views
  • 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.
  • K Offline
    K Offline
    krm26
    wrote on last edited by
    #1

    It seems like I must be missing something staggeringly obvious. Custom events, clearly visible in a QWidget's event method if I override it to take a look, never reach the customEvent method. Simply adding

    if event.type() >= QEvent.User:
        self.customEvent(event)
    

    to event makes everything work the way I expect it to. Is there some QApplication flag I need to set? All the Qt documentation indicates it is just a matter of setting the event type properly and overriding customEvent. Was customEvent secretly deprecated when QCustomEvent was? Feel like I'm going mad :-)

    -- an infrequent Qt user

    (Not that it should matter but obv. using Python binding)

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @krm26 said in Custom QEvent question:

      if I override it to take a look,

      What do you mean with this? What do you override where?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      K 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @krm26 said in Custom QEvent question:

        if I override it to take a look,

        What do you mean with this? What do you override where?

        K Offline
        K Offline
        krm26
        wrote on last edited by
        #3

        @Christian-Ehrlicher I mean if I override the event method in the object that I'm posting to I clearly see the posted custom event being properly dispatched. The customEvent method, however, is never called. Now, as I understand the architecture, it is expected for the event method to see (and ignore) custom events -- but it is also expected for the customEvent method to see them and house your custom event-handling logic.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Looks like you are using python. Which bindings are you using ?

          Can you provide a minimal runnable example that shows your issue ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            All is correct. QObject::event() is called for every event, QObject::customEvent() only for custom events.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            K 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              All is correct. QObject::event() is called for every event, QObject::customEvent() only for custom events.

              K Offline
              K Offline
              krm26
              wrote on last edited by
              #6

              @Christian-Ehrlicher What I said is that QObject.customEvent is NOT being called for custom events. QObject.event sees the custom events (and ignores them in its default implementation), QObject.customEvent is never called.

              Guess I'll source-dive the answer, thanks.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #7

                @krm26 said in Custom QEvent question:

                Guess I'll source-dive the answer, thanks.

                Not needed and I don't think you're right except somehwere else the event is already accepted:
                https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qobject.cpp.html#1298

                I would guess you simply forget to call the base class event() function when you've overwritten it.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                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