PDA

View Full Version : Memory problems by creating several QDialogs



H31MD4L90
8th June 2016, 17:03
Hi, at the moment I am working on a small game using Qt. It should stay quite simple, so I use QMainWindow for my main menu. From the menu you can open some QDialogs via pushButtons. I use the on_pushButton_clicked event to create a new object of the QDialog class and execute it.
Because I want the dialogs to be modal, I show them with exec() and close them via close().
To get no problems with the memory, I set the flag of every Dialog to Qt::WA_DeleteOnClose, to get sure to delete it. The problem is, everytime I close one, the program crashes.
Without setting the flag, it works perfectly fine.
Do you think its neccessary to delete them?

Thanks for your help ;)

anda_skoa
8th June 2016, 19:11
Maybe the dialog gets deleted twice?

You could be creating the dialog instances on the stack of the slot, or have passed a parent that gets deleted before the dialog gets closed, etc.

Cheers,
_

H31MD4L90
8th June 2016, 21:36
Currently *parent = 0 for all dialog classes I created.

I just can´t estimate how much of memory I waste, if I don´t delete a closed dialog. Do you know whether this could bring some problems or not?
Well, I know its at least not good style...

anda_skoa
9th June 2016, 06:59
Currently *parent = 0 for all dialog classes I created.

So you create the dialog with "new DialogClass" and have no delete anywhere?



I just can´t estimate how much of memory I waste, if I don´t delete a closed dialog. Do you know whether this could bring some problems or not?
Well, I know its at least not good style...

Sounds like a reasonable approach, but you seem to delete the dialog from to places

Cheers,
_