Re: C++ call constructor via GtkItemFactoryEntry



Jeff,

On Wed, 2003-02-05 at 14:30, Jeff Franks wrote:
For menu_items above to work ManageInvoices::displayWindow has to be a 
static function, since C doesn't know about classes.

It is a static function.

 Static class 
functions don't have a 'this' and don't know about 
construcors/destructors either. For a C function/struct like menu_items, 
I think you will have to write a static creation function, like 'init' 
to create an instance of your window. This is common practice in 
application Frameworks..

Good to know, and I went ahead and proceeded with the init method as it
was the only way I could get around my problems. Looks like it was the
preferred way.

2.) How can I call my C++ destructor during window closing?

You don't call destructors directly. If the window is a transient window 
just create it on the stack and the destructor will be called when it 
goes out of scope. If it is created by a call to 'new' you will have to 
call 'delete', which will call your destructor. You can then destroy any 
GTK+ C resources from inside the window's destructor. So in response to 
a user action to close the window, call something like 'delete window' 
and this call the window destructor.

I decided to use 
g_signal_connect(GTK_OBJECT(window),"destroy",&ManageInvoices::destroy,(void*)"WM destroy");

It's seems to work. Although I learned that the destructor is also
called as you mentioned above. So I ended up closing things out twice.
Nice seg fault to put me on the write path. I now and not using the
d'tor in favor of the destroy function.

I guess I could go about it either way, but not both as I learned the
hard way.

GTK+  provides the mechanism to add a C function to a widget that will 
get called when a widget is destroyed. You can use this function to call 
'delete'. This works no matter how the window is closed, by calling 
gtk_object_destroy() or by the window manager. (I can post some code if 
you need it.)
 
I do not think I need any code examples, if the snippet I mentioned
above is correct, or one way to go about it.

Thanks for the offer, and the assistance. Both are greatly appreciated.

-- 
Sincerely,
William L. Thomson Jr.
Support Group
Obsidian-Studios Inc.
439 Amber Way
Petaluma, Ca. 94952
Phone  707.766.9509
Fax    707.766.8989
http://www.obsidian-studios.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]