Qt Application Slowing Down
-
@swansorter I can't see the picture. File upload is broken here.
-
@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. -
Hi
Also check all the places where you use NEWvoid 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. -
Hi
Also check all the places where you use NEWvoid 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.@mrjj i tried this ....but know any changes ```
MainWindow *newmain=new MainWindow();
close();
newmain->show();
newmain->setAttribute( Qt::WA_DeleteOnClose); -
@mrjj i tried this ....but know any changes ```
MainWindow *newmain=new MainWindow();
close();
newmain->show();
newmain->setAttribute( Qt::WA_DeleteOnClose);@swansorter
To find memory leaks, before you go down thevalgrind
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 leveragingQtWidgets.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
QObject
s list, not just itsQWidget
s 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.... -
@swansorter
Hi.
Did you check all code?
All the dialogs etc
Also do you use new inside the dialogs ? -
@swansorter
Hi.
Did you check all code?
All the dialogs etc
Also do you use new inside the dialogs ?@mrjj yess am using new inside dialogs also
-
valgrind output
-
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. -
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. -
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.@mrjj yess am using 12kb size image
-
Hi
ok that's not so much.
look for new in loop and such places.How fast does it take to get "slow" ?
-
Hi
ok that's not so much.
look for new in loop and such places.How fast does it take to get "slow" ?
@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 -
@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@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. -
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 ?
-
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 ?
@SGaist i searched but found nothing ...
please share the link of any Qt example program -
@swansorter said in Qt Application Slowing Down:
please share the link of any Qt example program
-
@swansorter said in Qt Application Slowing Down:
please share the link of any Qt example program
@Christian-Ehrlicher i need example like QMainWindow with two or more dialogs.
-
Having two dialogs or one doesn't change things much.
What do you search exactly with an example with two dialogs ?
-
Having two dialogs or one doesn't change things much.
What do you search exactly with an example with two dialogs ?
@SGaist yea...qt dialog with more than two dialog