[sigc] signal connection problem
- From: cedric <cedric probesys com>
- To: libsigc-list gnome org
- Subject: [sigc] signal connection problem
- Date: Mon, 19 Apr 2004 09:30:40 +0200
Hi! I m a newbie in GTKmm and i have a problem connecting signals.
i read the libsigc++ docs on sourceforge.net but i didn t find the
answer :-(
just to remind you my application, here are its main caracteristics:
i have:
- a menubar.hh for the class description and menubar.cc for the
implementation.
it contains a method "addbutton" which can add the MenuElem passed in
parameter to the menubar.
- test.hh and test.cc: i should have named it "plugin" or "module"
instead of "test"...
for the moment, it just contains some infos to enable the creation of
a new button in the menubar.
- a main.cc file that lauch the window and load a module (here, the
"test" module).
in this exemple, we just want to add a new button in the menubar, and
to connect
this button to a method of the "test" class (the method "printtest").
In the "Test" class constructor, there is a variable which i initialize
like this:
ButtonName = new Gtk::Menu_Helpers::MenuElem("test",
Gtk::Menu::AccelKey("<control>t"),
SigC::slot(*this, &test::printtest) );
this variable is the one passed into parameter for call to the
MenuBar::addbutton(
"printtest" is a member method defined in the test.hh file as "virtual
void printtest();" it s supposed to write "test ok" in the terminal when
it is called, and it is supposed to be called when i click on the "test"
button in the menubar.
during the execution of my program, when i click on the "test" button,
nothing happens!
in fact, it seems that the connection isn t really made !?! I ve tried
everything: observe execution with debugers (anjuta's and ddd), i ve
tried different changes (they are commented in the following source),
and either i have "internal compilator error" or no effects when i press
the button... i m really out of ideas!
Here are my source files:
-----------------------------------begin
test.hh-------------------------------------------
#ifndef EASYGEST_TEST
#define EASYGEST_TEST
#include <gtkmm.h>
class test: public SigC::Object
{
public:
test();
virtual ~test();
virtual Gtk::Menu_Helpers::MenuElem getButtonName();
virtual void printtest();
Gtk::Menu_Helpers::MenuElem *ButtonName;
};
#endif
-----------------------------------end
test.hh-------------------------------------------
-----------------------------------begin
test.cc-------------------------------------------
#include <iostream>
#include "test.hh"
test::test()
{
std::cout << "test build" << std::endl;
ButtonName = new Gtk::Menu_Helpers::MenuElem("test",
Gtk::Menu::AccelKey("<control>t"),
SigC::slot(*this, &test::printtest) );
}
test::~test()
{
delete ButtonName;
}
Gtk::Menu_Helpers::MenuElem test::getButtonName()
{
return *ButtonName;
}
void test::printtest()
{
std::cout << "test ok" << std::endl;
}
-----------------------------------end
test.cc-------------------------------------------
-----------------------------------begin
menubar.hh-------------------------------------------
#ifndef EASYGEST_MENUBAR
#define EASYGEST_MENUBAR
#include <gtkmm.h>
//#include "test.hh"
class MenuBar : public Gtk::MenuBar
{
public:
MenuBar();
virtual ~MenuBar();
void addButton(Gtk::Menu_Helpers::MenuElem ButtonName);
// void addButton(test ButtonName);
protected:
//Signal handlers:
virtual void on_menu_deals_create_new();
//Child widgets:
Gtk::Menu m_Menu_Modules, m_Menu_Deals;
};
#endif
-----------------------------------end
menubar.hh-------------------------------------------
-----------------------------------begin
menubar.cc-------------------------------------------
#include <gtkmm/stock.h>
#include <iostream>
#include "menubar.hh"
//#include "test.hh"
MenuBar::MenuBar()
{//Fill menus:
//Modules menu:
{
Gtk::Menu::MenuList& menulist = m_Menu_Modules.items();
}
//Deals menu:
{
Gtk::Menu::MenuList& menulist = m_Menu_Deals.items();
menulist.push_back( Gtk::Menu_Helpers::MenuElem("Create a New Deal",
SigC::slot(*this, &MenuBar::on_menu_deals_create_new) ) );
}
//Add the menus to the MenuBar:
items().push_back( Gtk::Menu_Helpers::MenuElem("Modules",
m_Menu_Modules) );
items().push_back( Gtk::Menu_Helpers::MenuElem("Deals", m_Menu_Deals) );
show_all_children();
}
MenuBar::~MenuBar()
{
}
void MenuBar::on_menu_deals_create_new()
{
std::cout << "NEW DEAL" << std::endl;
}
void MenuBar::addButton(Gtk::Menu_Helpers::MenuElem ButtonName)
{
//add the button, but no connection...
Gtk::Menu::MenuList& menulist = m_Menu_Modules.items();
menulist.push_back(ButtonName);
}
/*
void MenuBar::addButton(test ButtonName)
{
Gtk::Menu::MenuList& menulist = m_Menu_Modules.items();
Gtk::Menu_Helpers::MenuElem toto("test",
Gtk::Menu::AccelKey("<control>y"),
SigC::slot(*ButtonName, &test::printtest));
menulist.push_back(toto);
// menulist.push_back( Gtk::Menu_Helpers::MenuElem("test",
Gtk::Menu::AccelKey("<control>t"),
// SigC::slot(*this, &test::printtest) ) );
}
*/
-----------------------------------end
menubar.cc-------------------------------------------
-----------------------------------begin
main.cc-------------------------------------------
#include <gtkmm.h>
#include <iostream>
#include "menubar.hh"
#include "test.hh"
void loadmodule ();
MenuBar *adrmenuBar;
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
window.set_title("interface easygest");
window.set_border_width(5);
window.set_default_size(800, 400);
Gtk::VBox vb;
window.add(vb);
MenuBar menuBar;
adrmenuBar=&menuBar;
vb.pack_start(menuBar, false, false, 0);
menuBar.show();
vb.show();
loadmodule ();
Gtk::Main::run(window);
return 0;
}
void loadmodule()
{
test toto ;
adrmenuBar->addButton(toto.getButtonName());
// adrmenuBar->addButton(toto);
}
-----------------------------------end
main.cc-------------------------------------------
thanks a lot to anyone who ll look at my problem!!!
cedric
ps: i was developping with glademm-2.2, because the 2.4 was unstable
before these days. but now that it seems to be stable, i ll try with it,
but i believe this has nothing to do with my case... :'(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]