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. ignoring qcloseevent before returning from function

ignoring qcloseevent before returning from function

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.3k Views 2 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i've seen in an existing code, when overriding closeEvent() of a window, such code:

    void Window:closeEvent(QCloseEvent *event) {
        // some code...
    
        if(/* some condition */) {
            event->ignore();
            return;
        }
    
        // some code...
    }
    

    what is the purpose of event->ignore(); here, if we return from the function anyways?

    mrjjM 1 Reply Last reply
    0
    • U user4592357

      i've seen in an existing code, when overriding closeEvent() of a window, such code:

      void Window:closeEvent(QCloseEvent *event) {
          // some code...
      
          if(/* some condition */) {
              event->ignore();
              return;
          }
      
          // some code...
      }
      

      what is the purpose of event->ignore(); here, if we return from the function anyways?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @user4592357

      Hi
      "void QEvent::ignore()
      Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
      Clearing the accept parameter indicates that the event receiver does not want the event.
      Unwanted events might be propagated to the parent widget."

      1 Reply Last reply
      4
      • U Offline
        U Offline
        user4592357
        wrote on last edited by user4592357
        #3

        that's what the documentation says, but what exactly does "unwanted events might be propagated to the parent widget." mean? we can JUST return from the function and thus show that the event receiver didn't want the event, right? what is changed (besides the accepted flag to false) when ignore() is called?

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

          @user4592357 said in ignoring qcloseevent before returning from function:

          unwanted events might be propagated to the parent widget." mean?

          It means that the event system will tell the widgets parent
          about the event since the child widget did not
          want it. You could also think like "Handled" about it.
          So if you say , "I will handle it", its not sent to your parent.
          But if you say , i wont handle it, the systems try the parents and and its parent etc.

          • what is changed (besides the accepted flag to false) when ignore() is called ?
            Nothing as far as i know. Its just a alias function for setAccepted(false)

          • we can JUST return from the function
            In theory yes. But in real life, its not the same as clearly stating i do not handle this event.

          as Doc says
          "It is set by default, but don't rely on this as subclasses may choose to clear it in their constructor."

          So do not count on it. Better to handle explicitly.

          1 Reply Last reply
          3

          • Login

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