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. Events during form close...
QtWS25 Last Chance

Events during form close...

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 5.0k 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    Quick question.

    Do signals on the main application finish before the application ~mainForm() happens when exiting the application?

    I know you usually want to wait for other threads to finish before prematurely destroying the active thread, but if you have a signal from another thread hitting the main application, is there a way to wait for those signals to finish before the main thread closes?

    I am getting an odd exception on my form close...that's the only reason why I am asking.

    Cheers!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Signals from other threads are not delivered directly, but via Qt's event system. So it may be that the object has been destroyed already. Instead of calling deleted directly on the object (delete xyz) you could schedule the destruction using Qt's event system by calling xyz->deleteLater(). It's just a guess, I did not test it.

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        [quote author="Volker" date="1327535529"]Instead of calling deleted directly on the object (delete xyz) you could schedule the destruction using Qt's event system by calling xyz->deleteLater(). It's just a guess, I did not test it.[/quote]

        This might solve the problem, but it is not guaranteed. If an object from another thread issues an async signal after deleteLater call, it will be put to the event queue after the delete call. So same issue.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GentooXativa
          wrote on last edited by
          #4

          You can try to catch the closing action checking
          @QCoreApplication::closingDown ()@
          If the application is closing, the value returns true.

          Another way is capturing the QEvent::close() on your QCoreApplication.

          Jose Vicente Giner Sanchez - Senior Mobile Developer

          www.gigigo.com

          C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
          T: +34 917431436

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            At application closeDown the form is most probably already destroyed.

            Using deleteLater() makes sure that the object is only deleted at the next run of the event loop - this usually happens when the slots directly connected to a signal have finished their work (unless you call processEvents manually). Every pending event directed to the object to be deleted is nuked in that case.

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

            1 Reply Last reply
            0
            • G Offline
              G Offline
              GentooXativa
              wrote on last edited by
              #6

              That's true @Volker. Thanks for your tip ^^

              By the way, i remember a signal named onClose but i cant find at documentation. But im sure i used it some time ago.

              Jose Vicente Giner Sanchez - Senior Mobile Developer

              www.gigigo.com

              C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
              T: +34 917431436

              1 Reply Last reply
              0
              • G Offline
                G Offline
                GentooXativa
                wrote on last edited by
                #7

                Nevermind, was a custom signal i made capturing the QEvent::close. :P

                Jose Vicente Giner Sanchez - Senior Mobile Developer

                www.gigigo.com

                C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
                T: +34 917431436

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vezprog
                  wrote on last edited by
                  #8

                  That is a great point Volker. Thank you all for your input. I will be testing this today.

                  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