Qt-interest Archive, January 2001
destructor isn't called
Message 1 in thread
Hello,
I've written a class inherited from QWidget
#include <qwidget.h>
#include <iostream.h>
<snip>
class Foo: public QWidget
{
public:
Foo();
~Foo();
....
//there are also slots, but they are not important to this problem
};
Foo::Foo()
{
//do something
}
Foo::~Foo()
{
cerr << "Destroying..." << endl;
}
</snip>
An instance of this class is the mainwidget of my application.
I thought, that if the Foo-object gets destroyed by the close memberfunction, the destructor will be called and "Destroying..." will be printed to console.
But it doesn't.
There are several possibilities why this could happen:
1) the destructor isn't called
sounds very strange
2) the 'cerr' - statement doesn't function in an destructor
sounds very strange
3) the Foo-destructor is overwritten by another Destructor
seems possible, because I'm using the moc
Is there anyone who have seen something like this before ?? Any hints ?
______________________________________________________________________________
Die Fachpresse ist sich einig: WEB.DE 15mal Testsieger! Kostenlos E-Mail,
Fax, SMS, Verschlüsselung, POP3, WAP....testen Sie uns! http://freemail.web.de
Message 2 in thread
"Stefan Mahlitz" wrote:
| An instance of this class is the mainwidget of my application.
| I thought, that if the Foo-object gets destroyed by the close memberfunction, the destructor will be called and "Destroying..." will be printed to console.
|
| But it doesn't.
Is the main widget the parent to your Foo-object?
--
[ signature omitted ]
Message 3 in thread
On Monday 08 January 2001 11:39, Stefan Mahlitz wrote:
> An instance of this class is the mainwidget of my application.
> I thought, that if the Foo-object gets destroyed by the close
> memberfunction, the destructor will be called and "Destroying..." will be
> printed to console.
QWidget::close() only destroyes the object if WDestructiveClose is passed as
a parameter the QWidget's ctor. Otherwise, the widget is only hidden.
Pieter van Beek
--
[ signature omitted ]
Message 4 in thread
kgw@cswgmbh.de schrieb am 08.01.01:
>
> Where is the needed Q_OBJECT-Macro invocation in this class. If that isn't present then the inheritance and all slots wont work as expected...
>
>
> regards
> Karl Günter Wünsch
>
It is there, I just forgot to write it in this email
And I too forgot to write that the constructor is
Foo::Foo():QWidget(....)
{
//do something
}
Sorry
Stefan Mahlitz
_______________________________________________________________________________
Alles unter einem Dach: Informationen, Fun, E-Mails. Bei WEB.DE: http://web.de
Die große Welt der Kommunikation: E-Mail, Fax, SMS, WAP: http://freemail.web.de
Message 5 in thread
No, the object itself is the mainwidget
#include <qapplication.h>
#include <foo.h>
int main (int argc, const char* args[])
{
QApplication myApp (argc, args);
Foo* fo = new Foo (0, "foo");
myApp.setMainWidget(fo);
fo->show();
myApp.exec();
return 0;
}
jou@trustix.com schrieb am 08.01.01:
> "Stefan Mahlitz" wrote:
>
> | An instance of this class is the mainwidget of my application.
> | I thought, that if the Foo-object gets destroyed by the close memberfunction, the destructor will be called and "Destroying..." will be printed to console.
> |
> | But it doesn't.
>
> Is the main widget the parent to your Foo-object?
>
>
> --
> Jo Uthus,
> VP of Engineering, Trustix
>
> --
> List archive and information: http://qt-interest.trolltech.com
______________________________________________________________________________
Die Fachpresse ist sich einig: WEB.DE 15mal Testsieger! Kostenlos E-Mail,
Fax, SMS, Verschlüsselung, POP3, WAP....testen Sie uns! http://freemail.web.de
Message 6 in thread
Pieter van Beek <vanbeek@kobasoft.nl> schrieb am 08.01.01:
> On Monday 08 January 2001 11:39, Stefan Mahlitz wrote:
>
> > An instance of this class is the mainwidget of my application.
> > I thought, that if the Foo-object gets destroyed by the close
> > memberfunction, the destructor will be called and "Destroying..." will be
> > printed to console.
>
> QWidget::close() only destroyes the object if WDestructiveClose is passed as
> a parameter the QWidget's ctor. Otherwise, the widget is only hidden.
>
> Pieter van Beek
The whole Application closes, that means, that the MainWidget has been destroyed, which is - in this case - my object fo of class Foo.
So I think fo has been destroyed, but without my provided destructor.
Stefan Mahlitz
______________________________________________________________________________
Die Fachpresse ist sich einig: WEB.DE 15mal Testsieger! Kostenlos E-Mail,
Fax, SMS, Verschlüsselung, POP3, WAP....testen Sie uns! http://freemail.web.de
Message 7 in thread
Stefan Mahlitz <Stefan.Mahlitz@web.de>
> The whole Application closes, that means, that the MainWidget has been
> destroyed, which is - in this case - my object fo of class Foo.
Qt does not delete top-level widgets unless you tell it to. If you set
WDestructiveClose, closing a top-level widget deletes it.
When the application closes, the windows are _closed_. Same word.
(Qt deletes child widgets when the parent widget is closed, but remember
that a top-level widget _has_ no parent.)
> So I think fo has been destroyed, but without my provided destructor.
In which case you should complain to your compiler vendor.
--Arnt
Message 8 in thread
On Monday 08 January 2001 13:16, you wrote:
> The whole Application closes, that means, that the MainWidget has been
> destroyed, which is - in this case - my object fo of class Foo.
I think this is getting more a C++ problem than a Qt problem
When you application 'closes' (I presume you mean that either you called
exit() or return from main()) and there are still objects on the heap, these
objects are NOT automagically destroyed! In fact, you have a memory leak.
Of course, modern operating systems (all of those qt runs on) will free all
memory that has been taken by the app. But don't expect dtors to be called.
Pieter.
Message 9 in thread
Thank you, but I found no Information about where to put the WDestructiveClose - Flag.
I'm using the QWidget::close (bool alsoDelete) function with alsoDelete = true, this calles my Destructor but produces core-dumps with bus-error.
It seems, that if the qapplication is being closed, it tries to destroy the MainWidget, which already has been destroyed.
I'm quite helpless here...
Stefan Mahlitz
_______________________________________________________________________________
Alles unter einem Dach: Informationen, Fun, E-Mails. Bei WEB.DE: http://web.de
Die große Welt der Kommunikation: E-Mail, Fax, SMS, WAP: http://freemail.web.de