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. [SOLVED] QDialog how to catch all close events?

[SOLVED] QDialog how to catch all close events?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 7.1k 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.
  • A Offline
    A Offline
    arsinte_andrei
    wrote on last edited by
    #1

    I have qDialog and on the @closeEvent(QCloseEvent *e) {}@ I can only catch if the user close the dialog from close button (x) only and not if the user cliched Ok or Cancel or hit the esc key. what event will do all this? I wist to emit a signal on the close event but reading the doc i've realised that the dialog will be hidden and not close on esc, Ok - accept(), or Cancel - reject(). hmm.. any good advise on how to catch all?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on last edited by
      #2

      ok I've solved myself I do not know if this is the best option but here it is a work around or a solution :P

      in dialog construct I have
      @connect(this, SIGNAL(accepted()), this, SLOT(onCloseDialog()));
      connect(this, SIGNAL(rejected()), this, SLOT(onCloseDialog()));
      connect(this, SIGNAL(dialogIsClosing()), this, SLOT(onCloseDialog()));@

      and this
      @void DialogName::closeEvent(QCloseEvent *event){
      emit dialogIsClosing();
      event->accept();
      }@

      and then
      @void DialogName::onCloseDialog{
      //what ever you want on the form hide or closing or rejected or accepted
      }@

      do not forget to add in the h file the emited signal for the close event.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fyngyrz
        wrote on last edited by
        #3

        If, when your dialog opens, you do this...

        this->setAttribute(Qt::WA_DeleteOnClose);
        

        ...then it will be closed, not hidden on any close event, etc., and in the...

        ~Dialog()
        

        ...function, you can do some closing things and they will be reliably carried out.

        JonBJ 1 Reply Last reply
        0
        • F fyngyrz

          If, when your dialog opens, you do this...

          this->setAttribute(Qt::WA_DeleteOnClose);
          

          ...then it will be closed, not hidden on any close event, etc., and in the...

          ~Dialog()
          

          ...function, you can do some closing things and they will be reliably carried out.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @fyngyrz
          Yes, but readers should beware that you have to be very careful about what you do in a destructor. Depending on your needs, you may be better dealing with signals & slots.

          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