PDA

View Full Version : QDialog modeless problem



sgtbash
1st May 2009, 09:34
Hi, i'm new at QT Developing. I read the C++ GUI Programming with C++ but i wasn't able to find the answer to my question.

I want to open my custom QDialog, it's a modeless and i'm not intrested in waiting its execution so i decided to open it with the show() method. This how i open it :



{
if (!dialog) {
dialog = new MyCustonDialog(this);
}
dialog->show();
dialog->raise();
dialog->activateWindow();
}


I have alse setted Qt::WA_DeleteOnClose on the dialog, so it must be destroyed when closed.

The problem is. The first time the dialog is opened it shows up correctly, but the second time, even if the destructor is called the dialog pointer is not NULL and the constructor is not called again causing a Segmentation Fault on the show() method.

How can i solve it?

If you're instrested in, i'm using Mac OS X Leopard with QT 4.5, and GCC 4.2.

caduel
1st May 2009, 09:56
either just do not delete it but just let it become hidden (no problem at all; it will just use a bit of memory...)

or

store the pointer to the dialog in a QPointer (always a good idea!) so you get "notified" (well, not you, but the QPointer) about the demise of the dialog and you do not end up with an invalid dangling pointer.

HTH

faldzip
1st May 2009, 18:47
delete only deletes object from memory and destructor is supposed to make some "cleaning", but none of them knows anything about pointers to that object, so there is no way to set the pointer to 0. You have to do it by yourself, or as it was said use QPointer instead of normal pointer, which is smarter and can set itself to 0 when the pointing object is deleted.

sgtbash
1st May 2009, 20:03
Thank you guys for your help!

The strangest thing was that for some object the pointer became null, and for other not. I googled a lot but i wasn't able to understand what was happening. Using a QPointer everything works perfectly!