GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Sep-2004, 09:55
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light

[FLTK] Proper way to close a window?


I have done several smallish programs in FLTK and I like it quite a bit. I want to start refining my programs and making them more robust.

I have a concern with how I am handling the exit out of a sub-window. Currently, I have a call back set for a dialog window like:

CPP / C++ / C Code:
void cb_track_exit(Fl_Widget*, void* data)
{
	track_dialog* d = (track_dialog*) data;

	d->wd_track->hide();
}

However, when I call the function again, I have this (which recreates it):

CPP / C++ / C Code:
void track_window() {

	track_dialog* d = new track_dialog;

So my concern is that every time I call this dialog, I am leaving it in memory when I exit. I can not for the life of me figure out how to properly close this though? Any suggestions?

PS - I will be posting several FLTK questions here. If there is enough interest in this topic, I may be able to talk J into opening up a subforum...
  #2  
Old 06-Sep-2004, 10:00
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Quote:
Originally Posted by dsmith
... I will be posting several FLTK questions here. If there is enough interest in this topic, I may be able to talk J into opening up a subforum...

You're the Progamming Forums Chief, just send me the memo and it will be done.
  #3  
Old 08-Sep-2004, 01:53
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 893
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by dsmith
CPP / C++ / C Code:
void cb_track_exit(Fl_Widget*, void* data)
{
	track_dialog* d = (track_dialog*) data;

	d->wd_track->hide();
}

However, when I call the function again, I have this (which recreates it):

CPP / C++ / C Code:
void track_window() {

	track_dialog* d = new track_dialog;

I know that when you call hide on all windows - that means closing the application, the proper destructors are called and the memory is properly freed, as oppose to exit.
However, I have no idea what happens when you call hide on a window while your program is still running .
Stand by, I'm thinking

Regards,
Luci

P.S:I am NOT a FLTK programmer (just seems a very simple Visual C )
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #4  
Old 18-Sep-2004, 06:43
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by dsmith
I have done several smallish programs in FLTK and I like it quite a bit. I want to start refining my programs and making them more robust.

I have a concern with how I am handling the exit out of a sub-window. Currently, I have a call back set for a dialog window like:

CPP / C++ / C Code:
void cb_track_exit(Fl_Widget*, void* data)
{
	track_dialog* d = (track_dialog*) data;

	d->wd_track->hide();
}

However, when I call the function again, I have this (which recreates it):

CPP / C++ / C Code:
void track_window() {

	track_dialog* d = new track_dialog;

So my concern is that every time I call this dialog, I am leaving it in memory when I exit. I can not for the life of me figure out how to properly close this though? Any suggestions?

I found a good response to my question. In retrospect, this is kind of a silly question, because the answer is kind of obvious.

The hide() function simply does not display the window/dialog box/widget anymore, but the resources are still there. So if you want to create the resources only one time and use the same ones over and over, then just using the hide() and show() functions should not cause a problem.

Unfortunately, the way that I have done my program, I create the resources each time I call the dialog box. (again - not the best way, but it does work). Therefore, when I "hide" my dialog box, I need to free these resources. In order to do this, I have changed my exit callback function to be:

CPP / C++ / C Code:
void cb_track_exit(Fl_Widget*, void* data)
{
  track_dialog* d = (track_dialog*) data;

  d->wd_track->hide();
  delete d->wd_track; 
  delete d;
}
  #5  
Old 13-Jul-2005, 11:46
edmundo_ba edmundo_ba is offline
New Member
 
Join Date: Jul 2005
Location: Buenos Aires, Argentina
Posts: 4
edmundo_ba is on a distinguished road
Quote:
Originally Posted by LuciWiz
I know that when you call hide on all windows - that means closing the application, the proper destructors are called and the memory is properly freed, as oppose to exit.
[/c]

Hello. If I have several windows opened, and I want to close the aplication, is it ok to just call exit(0)? what is the right way to do it?

ed
  #6  
Old 13-Jul-2005, 15:56
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Quote:
Originally Posted by edmundo_ba
Hello. If I have several windows opened, and I want to close the aplication, is it ok to just call exit(0)? what is the right way to do it?

ed

Technically, from what I understand. My opinion is, that if you can find your base application window and hide() it, then do that. That way, everything will be properly destroyed. FLTK takes care of widgets you create with new during it's lifespan so you don't need to handle those ones. That is the opinion that I have formed from reading the fltk newsgroups anyhow.

I have been using :

CPP / C++ / C Code:
mywidget->window();

You just need to be sure to setup your destructors to handle any delete (delete[]) 'ting that needs to be done on non-widget data. Once you hide the main window it's goodnite Irene for anything not handled.


Quote:
Originally Posted by the FLTK 1.1.x docs :
Fl_Window* Fl_Widget::window() const;

Returns a pointer to the primary Fl_Window widget. Returns NULL if no window is associated with this widget. Note: for an Fl_Window widget, this returns its parent window (if any), not this window.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
 
 

Recent GIDBlogHalfway done! by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:11.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.