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. Reliably save the state of a widget before it gets closed or destroyed()
Forum Updated to NodeBB v4.3 + New Features

Reliably save the state of a widget before it gets closed or destroyed()

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.0k Views 1 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.
  • J Offline
    J Offline
    jc-denton
    wrote on last edited by
    #1

    I have to save the state of a widget when it gets destroyed. However so far I thought about implementing just QWidget::closeEvent (..) , then I figured out that it doesn't get called for some strange reason. Next I tried to connect the QObject's destroyed signal, while it mentioned in the docs that it is emitted before the object is destroyed I had to figure out that it was actually after that, too late to save it's state. :(( So two questions:

    • If I click on the close button in windows, or close the program gracefully there is a way how Qt closes/removes it's widgets. How exactly does this work and which events/signals are to catch.

    • In a class derived from QWidget how can I do something before it gets closed or removed by it's parent. Destructor is not an option, since it might fail.

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

      have you testes protected destroy function of "QWidget":http://doc-snapshot.qt-project.org/4.8/qwidget.html#destroy ? It calls before object will be destroyed

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jc-denton
        wrote on last edited by
        #3

        no it doesn't

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

          QWidget::closeEvent get's called for top-level windows. Typically QDialog or QMainWindow, but also any widget that gets created/shown without a parent. So your widget seems to be a child widget?

          I'd still suggest using the destructor, what do you mean with "Destructor is not an option, since it might fail"? A destructor shouldn't fail...

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jc-denton
            wrote on last edited by
            #5

            So your widget seems to be a child widget?

            yes.

            Well it writes it's state into an XML file. So what if the file is does not exist anymore? Then I would just loose the state :(

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on last edited by
              #6

              [quote author="jc-denton" date="1336657863"]Well it writes it's state into an XML file. So what if the file is does not exist anymore? Then I would just loose the state :([/quote]

              Yeah but how would that change if using any other close-triggered signal/event and not the destructor? After all, If the file doesn't exist anymore, recreate it, if the state of the widget is so important.

              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