[Qt-interest] Designer Created Dialog
Ankit Agarwal
ankit17.ag at gmail.com
Fri Feb 6 08:12:20 CET 2009
HI,
There is a memory leak as you are creating a new dialog everytime in the
same variable and nor free ing the previousply allocated memory space.
This can be avoided simply by creating your dialog class as a singleton
class. So you do not create an new instance everytime you need to show that
dialog. you just create the instance once and use the same instance every
time you need to show the dialog.
On Fri, Feb 6, 2009 at 12:11 PM, Suryakiran Gullapalli <
Suryakiran.Gullapalli at ansys.com> wrote:
> Hello,
>
> With Qt - 4.4.3,
>
>
>
> I'm designing some dialogs using Qt Designer and from MainWindow's menu, I
> show these dialogs as and when required.
>
>
>
> it's like this
>
>
>
> MainWindow :: MainWindow()
>
> {
>
> ...
>
> connect(mainWindowMenuItem, SIGNAL(triggered()), this,
> SLOT(showParticularDialog()) ;
>
> ...
> }
>
>
>
> and in showParticularDialog(), I do this.
>
>
>
> void MainWindow :: showParticularDialog ()
>
> {
>
> QDialog *dialog = new SomeDialog(this) ;
>
> dialog->show() ;
>
> }
>
>
>
> This SomeDialog is declared like this in SomeDialog.hpp
>
>
>
> class SomeDialog : public QDialog, private Ui::SomeDialog
>
> {
>
> ...
> } ;
>
>
>
> Ui::SomeDialog is from ui_SomeDialog.h which is created by designer and
> uic.
>
>
>
> This works fine, but I found an issue with this. Whenever I trigger
> mainWindowMenuItem, a new QDialog will be created. Not only the memory
> consumption goes up, but also whatever changes I've made in that Dialog are
> gone. In the sense that the QDialog object is not persistent.
>
>
>
> I tried declaring QDialog* m_someDialog as a member of MainWindow class,
> and in its implementation,
>
>
>
> MainWindow :: MainWindow ()
>
> {
> ...
>
> m_someDialog = (QDialog*) 0 ;
>
> connect (mainWindowMenuItem, SIGNAL(triggered()), this,
> SLOT(showParticularDialog())) ;
>
> ...
>
> }
>
>
>
> and in
>
>
>
> void MainWindow :: showParticularDialog ()
>
> {
>
> if (!m_someDialog) m_someDialog = new SomeDialog (this) ;
>
> m_someDialog->show() ;
>
> }
>
>
>
> This seems to be working, till I close the application. At the time of
> closing the application, I get a crash with corrupted heap around mainw.
>
>
>
> How to get around this problem.
>
> Thanks in advance,
>
> Surya
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
--
Regards,
Ankit Agarwal
SW Engineer
Vegayan Systems
email : ankit_agarwal at vegayan.com
Blog : http://ankit17.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090206/5e5cdef6/attachment.html
More information about the Qt-interest-old
mailing list