這是我做的:
// create the UI
refUI = Gtk::Builder::create();
refUI->add_from_file(grq::GLADE_FILE);
// grab your widget
refUI->get_widget("but_new", but_new); // Gtk::ToolButton *but_new;
but_new->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_new_game));
// your signal handler looks something like this :)
void MainWindow::on_new_game() {}
編輯:
基本上*這是你會被調用函數信號處理程序的對象。
這是我的主要看上去像什麼:
int main(int argc, char **argv) {
Gtk::Main kit(argc, argv);
MainWindow main_window;
kit.run(*main_window.window);
return 0;
}
MainWindow
基本上是一個包裝的GtkWindow並定義窗口小部件,一個一類。 la:
class MainWindow
{
private:
Glib::RefPtr<Gtk::Builder> refUI;
//
// Widgets
//
Gtk::ToolButton *but_about;
public:
// The window. This is public so we can hook into events and
// call kit.run(window) against it, if needed.
Gtk::Window *window;
MainWindow()
{
// Load the data for this window and it's widgets.
refUI = Gtk::Builder::create();
refUI->add_from_file(grq::GLADE_FILE);
// The window
refUI->get_widget("main_window", window);
// Widgets
refUI->get_widget("but_about", but_about);
but_about->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_about));
...
}
virtual ~MainWindow()
{
if (window != NULL)
{
delete window; // Frees all the children for the window, too.
}
}
virtual void on_about()
{
// stuff
}
};
希望這會有所幫助!
http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-signals-overview.html.en雖然知道要連接的信號也不是微不足道的:S – 2010-11-27 16:20:44
對,我見過在很多地方......我沒有得到的是這個部分。 – stu 2010-11-29 01:29:58
在這種情況下,'這'是什麼? – stu 2010-11-29 01:30:16