Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TopWindow&PopUp, TrayIcon » Function holding a static TopWindow. Is it safe?
Function holding a static TopWindow. Is it safe? [message #45863] Fri, 15 January 2016 14:00 Go to next message
koldo is currently offline  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
SetMessage() is a function that opens a TopWindow showing a message in a list.

Is it safe to have a static TopWindow inside a function?

Could it be that when the program ends, CtrlCore could not close it?

What would be a safer/better way to do it?

class MessageWindow : public TopWindow {
	void SetMessage(const String message);
	~MessageWindow() 		{TopWindow::Close();}
	...
};

void SetMessage(const String message) {
	static MessageWindow window;
	
	window.SetMessage(message);	
}


Best regards
Iñaki
Re: Function holding a static TopWindow. Is it safe? [message #45864 is a reply to message #45863] Fri, 15 January 2016 16:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes, this is ok.

The rule is that it has to be constructed after APP_MAIN and destructed before APP_MAIN exit.
Re: Function holding a static TopWindow. Is it safe? [message #45866 is a reply to message #45864] Fri, 15 January 2016 19:56 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
mirek wrote on Fri, 15 January 2016 16:25
The rule is that it has to be constructed after APP_MAIN and destructed before APP_MAIN exit.
However the class is declared static inside a function so, would it be destructed after APP_MAIN?


Best regards
Iñaki
Re: Function holding a static TopWindow. Is it safe? [message #45868 is a reply to message #45866] Sat, 16 January 2016 07:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I am sorry, 'destructed' part is wrong. Thanks for pointing that out.

It is just 'constructed' after APP_MAIN.

BTW, you do not have to worry that much with current U++ - there is an ASSERT in Ctrl constructor... So if you break rules, it is runtime error in debug.

Mirek
Re: Function holding a static TopWindow. Is it safe? [message #45871 is a reply to message #45868] Sat, 16 January 2016 15:43 Go to previous message
koldo is currently offline  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
Thank you

Best regards
Iñaki

[Updated on: Sat, 16 January 2016 15:43]

Report message to a moderator

Previous Topic: Crashing when using MenuBar's
Next Topic: TrayIcon in Ubuntu 11.04 not shown.
Goto Forum:
  


Current Time: Thu Mar 28 13:36:27 CET 2024

Total time taken to generate the page: 0.02045 seconds