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. QObject::event() return value vs. QEvent::setAccepted()
QtWS25 Last Chance

QObject::event() return value vs. QEvent::setAccepted()

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 4.3k 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.
  • J Offline
    J Offline
    Jakob Schou
    wrote on last edited by
    #1

    Both the return value of QObject::event() and the accepted state of QEvent seems to indicate whether the event has been consumed or if the event may be propagated to a parent object (correct me if I am wrong!). What is the difference? Is there anything that can be accomplished with the QObject::event() return value that can't be accomplished with the accept state? (I may have misunderstood everything, please enlighten me...)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Most event handlers don't have a result value, so QEvent::setAccepted() is required for that. Mucking with the accept state in QObject::event() probably is bad practice, as event() is the function that delegates the QEvents to the proper handlers. In the end you can ignore the accept state in the event() function if you really need to.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Darryl DSouza
        wrote on last edited by
        #3

        Each QObject fiters the events of other objects. Best practice would be you get the event of your QObject and handle it the way you need it.

        Darryl D'Souza

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          [quote author="Jakob Schou" date="1297868973"]Both the return value of QObject::event() and the accepted state of QEvent seems to indicate whether the event has been consumed or if the event may be propagated to a parent object (correct me if I am wrong!). What is the difference? Is there anything that can be accomplished with the QObject::event() return value that can't be accomplished with the accept state? (I may have misunderstood everything, please enlighten me...)[/quote]

          See http://doc.qt.nokia.com/qq/qq11-events.html#acceptorignore :)

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jakob Schou
            wrote on last edited by
            #5

            Thanks. The link posted by peppe above explains how it works:

            "The "accept" flag is a communication mechanism between the specific event handlers and event(), whereas the bool return value of event() is used to communicate with QApplication::notify()."

            So basically the default event() method will "convert" the "accept" flag to its return value.

            1 Reply Last reply
            1
            • P Offline
              P Offline
              polo2024
              wrote on last edited by
              #6

              the link now is https://doc.qt.io/archives/qq/qq11-events.html

              Pl45m4P 1 Reply Last reply
              0
              • P polo2024

                the link now is https://doc.qt.io/archives/qq/qq11-events.html

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #7

                @polo2024 said in QObject::event() return value vs. QEvent::setAccepted():

                the link now is https://doc.qt.io/archives/qq/qq11-events.html

                So you came here because a link in an ancient topic, over 10 years old, is not valid anymore and you thought the OPs must see the "new" link right now?!
                (which leads to an archive anyway)

                Interesting.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                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