C++ call constructor via GtkItemFactoryEntry



Jumping in with both feet.

I have an app that each inner window is launched by the main app/window.
Each window has it's own class.

So far things are working the way I want them to for the most part.
However I need to deviate from how I am currently doing things.
Currently I call a function/method within the class directly from the
main GTK menu.

Ex:
GtkItemFactoryEntry menu_items[] = {
        {"/Manage/Invoices","<control>I",&ManageInvoices::displayWindow,0,null_gchar},
        {"/_Help",null_gchar,NULL,0,"<LastBranch>"},
        {"/Help/About",null_gchar,&About::displayWindow,0,null_gchar},
};

That works fine however I have a constructor to the class that does not
get called. I need the constructor/destructor to be called so DSO's can
be loaded/unloaded and my app work without a seg fault.

I could just put the DSO loading code in the displayWindow function, but
then I have to come up with a way to close out the DSO. Which currently
is handled by the destructor. I also am having problems with calling the
destructor.

So my questions are as follows. 

1.) How can I call a C++ constructor from within my GTK menu without
having to wrap it in another C or C++ function?

I thought about doing an init() function like
void ManageInvoices::init() {
        ManageInvoices mi = new ManageInvoices();
        mi.displayWindow;
}

Although I am not sure that's a good way to go, not to mention the
additional codding. Is it OK to have an object create a new version of
itself. Like in the above example?

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

Of course I can place a button on my new window and have it call some
function that will call the destructor and close the window. Although if
someone closes the window via the window managers close/X button I need
to detect that and call the destructor.

Neither my c'tors and d'tors take any arguments, and for some reason I
am thinking that a c'tor or d'tor is being called for the object/class
to exist when I see the window.

However I know that my c'tors and d'tors are not being called.

Further more I know I may not be doing things the best or proper way.
Currently I am still learning C/C++ and GTK in the process. So please be
kind in your responses if I am asking the obvious.

-- 
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]