[Kde-bindings] Simple KCrash question

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue Apr 27 11:23:25 UTC 2004


On Tuesday 27 April 2004 10:48, Martin Welch wrote:
> I, er, pinched this from the first kde3 app I found on kde.org to see
> how to do this. As you can see I've not changed it yet.
>
> I wondered if it's a) because I'm creating more than one top level
> window which the X server is unhappy with or b) it's a multi threading
> issue.
>
> If I unravel the code essentially I'm trying two things:
>
> First,
>
> CMainWindow::polish() // corresponds to SWF Form.Load
> {
> 	KMainWindow* w = new KMainWindow(0, "test", WDestructiveClose);
> 	w->show();
> }
>
> This works and creates the "test" main window before the main app
> window.
>
> However, if I connect a KPopupMenu like this:
>
> void CMainWindow::Connect(KPopupMenu* pMenu)
> {
> 	connect( pMenu, SIGNAL(activated(int)), SLOT(OnActivated(int))
> );
> }
>
> void CMainWindow::OnActivated(int id)
> {
> 	KMainWindow* w = new KMainWindow(0, "test", WDestructiveClose);
> 	w->show();
> }
>
> The fault occurs in the KMainWindow c-tor in OnActivated. The difference
> is that the main window is now visible - exec() is executing.
>
> Thanks for your help Richard.
>
> Martin
>
> -------------------------------------
> static const char description[] =
>     I18N_NOOP("A KDE RSS Feed Creator.");
>
> static const char version[] = "0.2.1";
>
> static KCmdLineOptions options[] =
> {
>     KCmdLineLastOption
> };
>
> extern "C" KApplication* Application_ctor(int argc, char** argv, char*
> rAppName)
> {
>     KAboutData about("krsseditor", I18N_NOOP("KRssEditor"), version,
> description,
>                      KAboutData::License_GPL, "(C) 2004 Reuben Sutton",
> 0, 0, "blinkdude at blinkdude.org.uk");
>     about.addAuthor( "Reuben Sutton", 0, "blinkdude at blinkdude.org.uk" );
>     KCmdLineArgs::init(argc, argv, &about);
>     KCmdLineArgs::addCmdLineOptions( options );
>
> //	_pApp = new KApplication(argc, argv, rAppName);
> 	_pApp = new KApplication();
>
> 	return _pApp;
> }

Well the logic is a bit strange in that you're creating a window in the 
polish() method of another KMainWindow, but I don't think that's wrong in 
itself.

Each KMainWindow should have a unique name, or if you add a '#' to the name it 
will append a number to make a unique name:

KMainWindow* w = new KMainWindow(0, "test#", WDestructiveClose);

And I think every window except the top one should have a parent:

KMainWindow* w = new KMainWindow(myparent, "test#", WDestructiveClose);

That's all I could see from looking at the code snippets - if it still doesn't 
work, maybe post the complete source/makefile so I could try it out.

-- Richard



More information about the Kde-bindings mailing list