[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: trivial KDE program crashing
From:       David Watson <dgwatson () kent ! edu>
Date:       2001-09-09 1:19:03
[Download RAW message or body]

I'm pretty sure that all QWidgets need to be allocated on the heap, not the 
stack, because of the auto-deletion stuff - your KApplication deletes the 
KMainWindow (that's why you pass a pointer). Since you dynamically allocated 
your main window in the non-crashing version, it's fine when it gets deleted.

Basically, you need to use new for all widgets, and you DON'T delete them 
manually (except in certain cases), because QT does it for you when the 
parent is destroyed.

Hope this helps :).

-David



On Saturday 08 September 2001 08:01 pm, George Petri wrote:
> Hi!
>
> I am experienced in C++ but am a complete newbie to KDE programming.
> I was wondering if anyone knows why the following program crashes _on
> exit_?:
>
> #include <kmainwindow.h>
> #include <kapp.h>
>
> int main (int argc, char *argv [])
> {
>         KApplication app (argc, argv, "Test");
>         KMainWindow window;
>         app.setMainWidget (&window);
>         window.show ();
>         return app.exec ();
> }
>
> It produces the following backtrace:
> 0x40acae39 in wait4 () from /lib/libc.so.6
> #0  0x40acae39 in wait4 () from /lib/libc.so.6
> #1  0x40b2b8e0 in __check_rhosts_file () from /lib/libc.so.6
> #2  0x4061030d in KCrash::defaultCrashHandler () from
> /usr/lib/libkdecore.so.3
>
> #3  0x40a68008 in sigaction () from /lib/libc.so.6
> #4  0x40a03ff4 in __builtin_delete () from
> /usr/lib/libstdc++-libc6.1-2.so.3 #5  0x407819b8 in
> KMainWindow::~KMainWindow () from /usr/lib/libkdeui.so.3 #6  0x4025ca04 in
> QWidget::close () from /usr/lib/libqt.so.2
>
> If I make "window" a pointer, then it doesn't crash at all:
>
> #include <kmainwindow.h>
> #include <kapp.h>
>
> int main (int argc, char *argv [])
> {
>         KApplication app (argc, argv, "Test");
>         KMainWindow *window = new KMainWindow;
>         app.setMainWidget (window);
>         window->show ();
>         return app.exec ();
> }
>
> Why is this so?  Wouldn't this cause a memory leak?
>
> Thanks in advance,
> George
>
> >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> >> unsubscribe <<
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic