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. problem opening one instance of every Widget(form) and deleting it ...

problem opening one instance of every Widget(form) and deleting it ...

Scheduled Pinned Locked Moved Solved General and Desktop
qwidgetformqt5.6releasedeletelater
9 Posts 3 Posters 947 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on last edited by Proton Phoenix
    #1

    Hi ~~~
    i have multi forms ... and mainwindow .. with a Menu inside it a lot of buttons .. every button connected with a special form
    i want if i click to a button it opens the needed form only one time (one instance) .. and if i close it it release the memory ... if i open it once again it open ...
    every form i want it to open just one instance ...
    for example
    this would open new instance everytime i clicked and clear memory without problem

    activatesoft* actsoft = new activatesoft();
        actsoft->show();
        actsoft->setAttribute(Qt::WA_DeleteOnClose);
    

    //////mainwindow.h

    class MainWindow : public QMainWindow
    {
        Q_OBJECT
        benefits* benefit=NULL;
    // if i set this as private variable the software crashes if i open the form second time (after one close)
    }
    

    //////mainwindow.cpp

    MainWindow::~MainWindow()
    {
        delete ui;
    //// i tried this too delete benefit but it doesn't work
        benefit->deleteLater();
    }
    
    and this :
     if (!benefit)
        benefit = new benefits();
        benefit->show();
    

    would open just one instance but even if i delete it it doesn't release the used memory

    is there any solution

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      How did you check that deleteLater() (or a direct delete) does not work?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      P 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        How did you check that deleteLater() (or a direct delete) does not work?

        P Offline
        P Offline
        Proton Phoenix
        wrote on last edited by Proton Phoenix
        #3

        @Christian-Ehrlicher

        the same yes it doesn't work may be my problem was i deleting it on mainwindow destructor .. not benefit one ...
        mainwindow is the parent
        if i put the instance as private variable .. it release the memory once the window closes ... but if i open it once again the software crashes

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please re-read your last post and think about it if anyone except you understands what you're trying to tell us.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          P 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            Please re-read your last post and think about it if anyone except you understands what you're trying to tell us.

            P Offline
            P Offline
            Proton Phoenix
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            i have multi forms ... and mainwindow .. with a Menu inside it a lot of buttons .. every button connected with a special form
            i want if i click to a button it opens the needed form only one time (one instance) .. and if i close it it release the memory ... if i open it once again it open ...
            every form i want it to open just one instance ...

            JonBJ 1 Reply Last reply
            0
            • P Proton Phoenix

              @Christian-Ehrlicher

              i have multi forms ... and mainwindow .. with a Menu inside it a lot of buttons .. every button connected with a special form
              i want if i click to a button it opens the needed form only one time (one instance) .. and if i close it it release the memory ... if i open it once again it open ...
              every form i want it to open just one instance ...

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

              @Proton-Phoenix
              In a word: why don't you just have an instance (not a pointer to) of this widget/form in your main window? No need to new or delete . One instance.. Sounds like just what you want?

              P 1 Reply Last reply
              2
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Then don't delete it on close and re-open this instance later on - basic c++ stuff, nothing Qt-specific.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • P Offline
                  P Offline
                  Proton Phoenix
                  wrote on last edited by
                  #8

                  Thank you so much for helping i will try that
                  i still new on c++
                  just trying bruce lee methods to learn things as it can be when i hit a barrier .. i search for solution ... until i reach most of its database

                  Thank you all of you

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Proton-Phoenix
                    In a word: why don't you just have an instance (not a pointer to) of this widget/form in your main window? No need to new or delete . One instance.. Sounds like just what you want?

                    P Offline
                    P Offline
                    Proton Phoenix
                    wrote on last edited by
                    #9

                    @JonB it works bro thank you
                    problem fixed
                    when i tried this before it doesn't open the window at all ... just flashing but now i understand why it's working
                    Thank you <3

                    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