Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

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

    General and Desktop
    qwidget form qt5.6 release deletelater
    3
    9
    317
    Loading More Posts
    • 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
      Proton Phoenix last edited by Proton Phoenix

      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 Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

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

        Qt has to stay free or it will die.

        P 1 Reply Last reply Reply Quote 1
        • P
          Proton Phoenix @Christian Ehrlicher last edited by Proton Phoenix

          @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 Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

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

            Qt has to stay free or it will die.

            P 1 Reply Last reply Reply Quote 1
            • P
              Proton Phoenix @Christian Ehrlicher last edited by

              @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 ...

              JonB 1 Reply Last reply Reply Quote 0
              • JonB
                JonB @Proton Phoenix last edited by 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 1 Reply Last reply Reply Quote 2
                • Christian Ehrlicher
                  Christian Ehrlicher Lifetime Qt Champion last edited by

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

                  Qt has to stay free or it will die.

                  1 Reply Last reply Reply Quote 2
                  • P
                    Proton Phoenix last edited by

                    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 Reply Quote 0
                    • P
                      Proton Phoenix @JonB last edited by

                      @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 Reply Quote 0
                      • First post
                        Last post