help: add handler to a menuitem



I am a gtkmm and glade new bie.
I met a problem in adding handler to a menuitem.
I created menu in a glade file using glade 3.6.7. and I wanted to add a handler function to menuitem.
 
I created a class in header file like following:
 

class gkass
{
      public:
             gkass();
            
             Gtk::Window* get_window();
             virtual ~gkass();
                         
      private:
              Gtk::Window* gkassWindow;
              int load_ui();
              int connect_signals();
             
              Gtk::Menu*  mnuGlobal;
              Gtk::MenuItem* mnuGlobalConfig;
 &n bsp;            Gtk::Button*  test;              
              
              void  on_mnuGlobalConfig_activate();
};
 
 

And in .cc file I wrote:


#include "gkass.h"
 

gkass::gkass()
{
      load_ui();
      connect_signals();
}

gkass::~gkass()
{
 delete gkassWindow;
}

int gkass::load_ui()
{

    //Load the GtkBuilder file and instantiate its widgets:
    Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
   
    try
    {         //load xml file
        refBuilder->add_from_file(glade_file_name);

    }
    catch(const Glib::FileError & ex)
    {
        std::cerr << "FileError: " << ex.what() << std::endl;
        return 1;
    }
    catch(const Gtk::BuilderError & ex)
    {
        std::cerr << "BuilderError: " << ex.what() << std::endl;
        return 1;
    }

    //Get the GtkBuilder-instantiated Window: wndPersonalConfig, wndGlobalConfig, main_window
    refBuilder->get_widget("main_window", gkassWindow);
    refBuilder->get_widget("menu1", mnuGlobal);   
    refBuilder->get_widget("imnuGlobalConfig", mnuGlobalConfig);

    
    return 0;

}

int gkass::connect_signals()
{
   g_signal_connect( G_OBJECT(mnuGlobalConfig), "activate",
          G_CALLBACK(on_mnuGlobalConfig_activate), NULL);     // this line will lead to an error when compiling
   

   return 0;
  
}

 

Gtk::Window* gkass::get_window()
{
 return gkassWindow;
}

 

void gkass::on_mnuGlobalConfig_activate()
{
     Gtk::MessageDialog aa("This is mnuGlobalConfig.",
                    FALSE,
                    Gtk::MESSAGE_INFO,
                    Gtk::BUTTONS_OK,
                    TRUE);
     aa.run();
}

 

When compiling , an error occurs that :  In member function `int gkass::connect_signals()':  argument of type `void (gkass::)()' does not match `void (*)()'

 

I can not found any solutions using above method by Google. The examples all adds menuitems in code file, not in glade file. So please help me. 

 

wallace.lee   wallace lee hotmail com

2009-9-2



聊天+搜索+邮箱 想要轻松出游,手机MSN帮你搞定! 立刻下载!


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