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 second window when closed

How to destroy second window when closed

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

    hello,

    I'm working on a new qt project, and I need to be sure to manage correctly the memory allocation and the resources. Just want to ask if someone can give me some suggestion about the way to correctly close a second window, opened from the main window, in particular I need to de-allocate the memory when window is closed.

    Thanks for the support
    Davide

    raven-worxR 1 Reply Last reply
    0
    • D davidesalvetti

      hello,

      I'm working on a new qt project, and I need to be sure to manage correctly the memory allocation and the resources. Just want to ask if someone can give me some suggestion about the way to correctly close a second window, opened from the main window, in particular I need to de-allocate the memory when window is closed.

      Thanks for the support
      Davide

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @davidesalvetti
      there are multiple ways to achieve this.

      1. you can set the parent of the secondary window to the mainwindow. And on the main window set the Qt::WA_DeleteOnClose widget attribute. Then the secondary window is closed automatically when the mainwindow is closed.
      2. do it manually at any time by keeping a pointer to the secondary window and call close() on it
      3. ...

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        For modal dialogs you normally just allocate on the stack, and call the blocking exec (with a bit of caution)

        for any other sub window you can use setAttribute(Qt::WA_DeleteOnClose);

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • D Offline
          D Offline
          davidesalvetti
          wrote on last edited by
          #4

          thank you a lot for the fast reply! It works now.

          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