[Qt-interest] Modal dialogs and their variable still exists after the EXEC?
Israel Brewster
israel at frontierflying.com
Tue Apr 7 19:02:07 CEST 2009
On Apr 6, 2009, at 11:42 PM, Giancarlo Amati wrote:
> Hello everybody,
>
> I have this code:
>
> CPointRegDlg *ptrDlg = new CPointRegDlg();
> ptrDlg->setModal(true);
> int accept = ptrDlg->exec();
> PointList l1 = ptrDlg->getSourceList();
>
>
> where ptrDlg is my dialog window derived from a QDialog and I call
> the exec() function as I want a Modal execution. Now, I wonder if
> after having called the function I still have the access to its
> members variable, one of them accessed by getSourceList() (I created
> this function) or the memory is deallocated after the execution.
> The problem I have is that l1 is always NULL and it shouldn't.
No, the memory is not deallocated until you call delete on ptrDlg. As
such, you need to make sure that you call delete on it somewhere in
your code, or else you have a memory leak. The only exception to this
(that I am aware of) would be if you have a Qt object with a parent
defined - in that case, the child object would be deleted when the
parent object is. However, here you have no parent defined for your
object, and even if you did it is not being deleted, so your object
remains intact. As mentioned by one of the other respondents, if the
memory had been deallocated, you should be getting a segfault on
calling getSourceList, not NULL. Use the debugger to trace the
execution of the getSourceList() function and make sure it is
performing as expected. If that looks right, you will need to go back
farther and look at where the member variable is set.
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
>
>
> Kind Regards.
> Giancarlo
>
> Il remix esclusivo di Messenger. Scaricalo gratis!
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090407/56dc6f16/attachment.html
More information about the Qt-interest-old
mailing list