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. Qt Application Slowing Down
Forum Updated to NodeBB v4.3 + New Features

Qt Application Slowing Down

Scheduled Pinned Locked Moved Solved General and Desktop
47 Posts 7 Posters 6.5k Views 3 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.
  • mrjjM mrjj

    Hi
    What are on these screens?

    Maybe you leak memeory?

    Could you show some code?

    S Offline
    S Offline
    swansorter
    wrote on last edited by swansorter
    #5

    @mrjj how to fix this memory leak?

    jsulmJ 1 Reply Last reply
    0
    • S swansorter

      @mrjj how to fix this memory leak?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @swansorter said in Qt Application Slowing Down:

      how to fix this memory leak?

      Which memory leak? Did you identify the leak already?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 2 Replies Last reply
      0
      • jsulmJ jsulm

        @swansorter said in Qt Application Slowing Down:

        how to fix this memory leak?

        Which memory leak? Did you identify the leak already?

        S Offline
        S Offline
        swansorter
        wrote on last edited by swansorter
        #7
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @swansorter said in Qt Application Slowing Down:

          how to fix this memory leak?

          Which memory leak? Did you identify the leak already?

          S Offline
          S Offline
          swansorter
          wrote on last edited by
          #8
          This post is deleted!
          jsulmJ 1 Reply Last reply
          0
          • S swansorter

            This post is deleted!

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #9

            @swansorter I can't see the picture. File upload is broken here.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            0
            • jsulmJ jsulm

              @swansorter I can't see the picture. File upload is broken here.

              S Offline
              S Offline
              swansorter
              wrote on last edited by
              #10

              0_1562932786841_Screenshot from 2019-07-12 17-24-21-min.png

              jsulmJ 1 Reply Last reply
              0
              • S swansorter

                0_1562932786841_Screenshot from 2019-07-12 17-24-21-min.png

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #11

                @swansorter I'm not sure what I should do with this screen-shot?
                If you think you have a memory leak then you have to analyse your app to find out where it is.
                You can use valgrind on Linux for that.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                3
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  Hi
                  Also check all the places where you use NEW

                  void settingDialog::on_ESCSettingbutton_clicked()
                  {
                  
                  // Show the MainWindow (i.e. the parent window)
                  MainWindow *newmain=new MainWindow();
                  close();
                  newmain->show();
                  }
                  

                  this leaks a mainwindow each time ESC is pressed.

                  so make sure you use
                  setAttribute( Qt::WA_DeleteOnClose);
                  all places where you NEW.

                  S 1 Reply Last reply
                  3
                  • mrjjM mrjj

                    Hi
                    Also check all the places where you use NEW

                    void settingDialog::on_ESCSettingbutton_clicked()
                    {
                    
                    // Show the MainWindow (i.e. the parent window)
                    MainWindow *newmain=new MainWindow();
                    close();
                    newmain->show();
                    }
                    

                    this leaks a mainwindow each time ESC is pressed.

                    so make sure you use
                    setAttribute( Qt::WA_DeleteOnClose);
                    all places where you NEW.

                    S Offline
                    S Offline
                    swansorter
                    wrote on last edited by
                    #13

                    @mrjj i tried this ....but know any changes ```
                    MainWindow *newmain=new MainWindow();
                    close();
                    newmain->show();
                    newmain->setAttribute( Qt::WA_DeleteOnClose);

                    JonBJ 1 Reply Last reply
                    0
                    • S swansorter

                      @mrjj i tried this ....but know any changes ```
                      MainWindow *newmain=new MainWindow();
                      close();
                      newmain->show();
                      newmain->setAttribute( Qt::WA_DeleteOnClose);

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

                      @swansorter
                      To find memory leaks, before you go down the valgrind or similar route, which is great but a bit intimidating. If you suspect that your leaks are from Qt GUI elements (which sounds like the case here?), you can get to see some really useful potential offenders by leveraging QtWidgets.QApplication.allWidgets() in your code, calling it at useful stages.

                      I wrote the following for my code (Python/PyQt, but you can easily translate to C++):

                      def debugWidgetsInUse():
                          # Function to allow to see what widgets are currently existing/in use from Qt
                          # This can be used to help to detect if there are any "leaks"
                      
                          allWidgets = QtWidgets.QApplication.allWidgets()
                          errfunctions.uiLogger.debug("Existing widgets: {}".format(len(allWidgets)))
                      
                          allDialogs = [w for w in allWidgets if isinstance(w, QtWidgets.QDialog)]
                          for dlg in allDialogs:
                              errfunctions.uiLogger.debug("Existing dialog: {} ({}) ({})".format(
                                  str(type(dlg)), dlg.windowTitle(), "visible" if dlg.isVisible() else "invisible"))
                      
                          allOrphans = [
                              w for w in allWidgets
                              if w.parent() is None
                              and not isinstance(w, QtWidgets.QDesktopWidget)
                              and not isinstance(w, QtWidgets.QMainWindow)
                          ]
                          for w in allOrphans:
                              text = w.objectName()
                              if text == "":
                                  if hasattr(w, "text"):
                                      text = w.text()
                              descendants = [
                                  descendant for descendant in allWidgets
                                  if descendant != w and w.isAncestorOf(descendant)
                              ]
                              errfunctions.uiLogger.debug("Orphan widget: {} ({}) ({} descendant(s))".format(
                                  str(type(w)), text, len(descendants)))
                      

                      I call this from time to time (e.g. after any window/dialog closure), and it has allowed me to easily spot a whole class of leaks.

                      It would be great if Qt allowed you to walk its QObjects list, not just its QWidgets list, but it doesn't provide access to that, so you can only spot widget leaks. But I can say this simple approach has allowed me to easily spot GUI leaks, which may be (at least part of) what you might want to look for....

                      1 Reply Last reply
                      3
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #15

                        @swansorter
                        Hi.
                        Did you check all code?
                        All the dialogs etc
                        Also do you use new inside the dialogs ?

                        S 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @swansorter
                          Hi.
                          Did you check all code?
                          All the dialogs etc
                          Also do you use new inside the dialogs ?

                          S Offline
                          S Offline
                          swansorter
                          wrote on last edited by
                          #16

                          @mrjj yess am using new inside dialogs also

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            swansorter
                            wrote on last edited by
                            #17

                            valgrind output
                            0_1563014260823_Screenshot from 2019-07-13 16-06-28-min.png

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

                              First please don't post screenshots!
                              Second as you can see there are 4GB of allocated memory. So it looks like you're allocating memory but forgot to delete them somewhere.

                              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
                              4
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #19

                                Hi
                                Do you use any images in your app ? load them etc ?
                                Not icons but huge images or similar ?
                                To use 4GB you have to have something a bit heavy as
                                clicking back and forth to leak that much using only widgets seems
                                to would take a long time.
                                You have to look over all places again and try to guess where it is not assigned a parent
                                and/or not flagged for delete on close.

                                S 1 Reply Last reply
                                1
                                • mrjjM mrjj

                                  Hi
                                  Do you use any images in your app ? load them etc ?
                                  Not icons but huge images or similar ?
                                  To use 4GB you have to have something a bit heavy as
                                  clicking back and forth to leak that much using only widgets seems
                                  to would take a long time.
                                  You have to look over all places again and try to guess where it is not assigned a parent
                                  and/or not flagged for delete on close.

                                  S Offline
                                  S Offline
                                  swansorter
                                  wrote on last edited by
                                  #20

                                  @mrjj yess am using 12kb size image

                                  1 Reply Last reply
                                  0
                                  • mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #21

                                    Hi
                                    ok that's not so much.
                                    look for new in loop and such places.

                                    How fast does it take to get "slow" ?

                                    S 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      Hi
                                      ok that's not so much.
                                      look for new in loop and such places.

                                      How fast does it take to get "slow" ?

                                      S Offline
                                      S Offline
                                      swansorter
                                      wrote on last edited by swansorter
                                      #22

                                      @mrjj within 5 min it starts getting slow
                                      once i got to main window application works normal speed for another 5 min
                                      and again if i back and forth the some other dialog it become slower

                                      mrjjM 1 Reply Last reply
                                      0
                                      • S swansorter

                                        @mrjj within 5 min it starts getting slow
                                        once i got to main window application works normal speed for another 5 min
                                        and again if i back and forth the some other dialog it become slower

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #23

                                        @swansorter
                                        Ok. That's pretty fast.
                                        Does seems related to navigating the app.
                                        I would set breakpoints in all dialogs destructors to make sure they are deleted.
                                        and generally, look over the code verify that you free stuff.

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

                                          Hi,

                                          From the look of the code you posted, you are re-creating at least your main window each time you call your settings dialog. If you do that with all your dialogs and maybe other widgets, it's not really surprising that the memory gets eaten up.

                                          You should take a look at the more complex Qt example on how to handle a QMainWindow with one or more dialogs.

                                          Still based on your code and ve fact that you are using images, how are you handling them ?

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

                                          S 1 Reply Last reply
                                          4

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved