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 » Community » Newbie corner » Multiple main windows, but only one active (Multiple main windows, but only one active)
Multiple main windows, but only one active [message #48578] Tue, 01 August 2017 00:36 Go to next message
Jose Luis is currently offline  Jose Luis
Messages: 3
Registered: February 2015
Junior Member
Hi,
This is my first message on the forum.
I'm making an application in which I want to be able to open a new main window and close the previous one.
That is, I want to re-run my program from scratch without having to close it or reset all variables manually.
I use next code:

UI_APP_MAIN
{
(new App)->OpenMain();
Ctrl::EventLoop();
}

And I call next function to close the active main windows and open another main window:

void App::CloseAndOpen()
{
delete this;
(new App)->OpenMain();
}

The function CloseAndOpen seems to work correctly if I only use it once or twice, but I have tried it intensively, and after several consecutive calls the program fails and closes (not always at the same number of consecutive calls).
Can be the failure caused by the repetitive and consecutive use of OpenMain()?
Is there any better way to get what I want ?. Is something missing from my code?
Thanks.
Re: Multiple main windows, but only one active [message #48579 is a reply to message #48578] Tue, 01 August 2017 10:49 Go to previous messageGo to next message
Jose Luis is currently offline  Jose Luis
Messages: 3
Registered: February 2015
Junior Member
After several tests, I got the program not to fail, but I had to use:

GUI_APP_MAIN
{
App().Run();
}

And:

void App::CloseAndOpen()
{
//Here I initialize variables, etc., to their initial values.
}

This way the program does not fail. But it was not the method which I would like to have applied.

Jose Luis

Re: Multiple main windows, but only one active [message #48580 is a reply to message #48579] Tue, 01 August 2017 11:30 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
bool wantCloseAndOpen;

GUI_APP_MAIN
{
  wantCloseAndOpen = true;
  while(wantCloseAndOpen) {
    wantCloseAndOpen = false;
    App().Run();
   }
}

void App::CloseAndOpen()
{
  wantCloseAndOpen = true;
  Break();
}



regards
omari.
Re: Multiple main windows, but only one active [message #48581 is a reply to message #48580] Tue, 01 August 2017 11:55 Go to previous messageGo to next message
Jose Luis is currently offline  Jose Luis
Messages: 3
Registered: February 2015
Junior Member
Thanks.
Your code works OK.
Regards,
Jose Luis
Re: Multiple main windows, but only one active [message #48583 is a reply to message #48581] Tue, 01 August 2017 16:09 Go to previous message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
You are welcome.

regards
omari.
Previous Topic: Modify richedit component of Uword demo
Next Topic: Cross-compiling for Raspbian
Goto Forum:
  


Current Time: Fri Mar 29 07:23:49 CET 2024

Total time taken to generate the page: 0.01411 seconds