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. How to destroy a dialog when the window of that dialog is closed?
Forum Updated to NodeBB v4.3 + New Features

How to destroy a dialog when the window of that dialog is closed?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.7k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    So i am showing a dialog this way:

    .h file
    @private:
    preferences *Preferences;@

    .cpp file
    @Preferences = new preferences(this);
    Preferences->exec();@

    but when the user closes the dialog with (X) the ram that this dialog has taken does not decrease,
    neither integers (that has been changed before clicking the (X) ) get reseted to their starting value.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      @delete preferences;@
      after exec ?

      But in that case, why keep a pointer to it in your class if you want to destroy it right after use ?

      You can also do:
      @
      Preferences preferences;
      preferences.exec();
      @

      preferences will get destroyed when going out of scope.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        You dialog has "class scope" so when your class holding the pointer is still active, it will keep the dialog in memory. Use a local scope like sGalst says.
        Greetz

        Greetz, Jeroen

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #4

          u sure when i have
          @private:
          preferences *Preferences;@

          its
          @ preferences.exec();@

          and not
          @ Preferences.exec();@

          eitherway i do it, i get always an error like
          @error: expected ';' before 'preferences'
          @

          [quote author="SGaist" date="1375712475"]Hi,

          @delete preferences;@
          after exec ?

          But in that case, why keep a pointer to it in your class if you want to destroy it right after use ?

          You can also do:
          @
          Preferences preferences;
          preferences.exec();
          @

          preferences will get destroyed when going out of scope.

          Hope it helps[/quote]

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            WELL IF THIS ISN'T WEIRD

            i went with the delete way

            i tested with my task manager besides and i saw that memory usage goes up, but doesn't goes down when u close the dialog

            BUT, when i did the same while recording with "Record my desktop" the memory went down immediatly

            PLEASE EXPLAIN ME what is going on :/
            Ubuntu 13.04 here

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sorry for the letter case mixing, my classes name always starts with an upper cased letter (like in Qt).

              The memory freed by the application is not always directly returned to the OS and that can have several reasons: reuse of the memory segment, memory page lock etc...

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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