gtkmmで作成した簡単なgtk +アプリケーションがあります。ボタンを押すとウィンドウの内容を変更したいので、そのコードを別のファイル(changeTitle.cc)に入れたいと思います。そのファイルから「ボタン」オブジェクトにアクセスするにはどうすればよいですか?他のファイルからGTKMMウィジェットにアクセスするには?
main.cc:
#include <iostream>
#include "buttons.h"
#include <gtkmm/application.h>
int main(int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app =
Gtk::Application::create(argc, argv,
"org.gtkmm.examples.base");
Buttons buttons;
return app->run(buttons);
}
buttons.h:
#ifndef GTKMM_EXAMPLE_BUTTONS_H
#define GTKMM_EXAMPLE_BUTTONS_H
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/box.h>
class Buttons : public Gtk::Window
{
public:
Buttons();
virtual ~Buttons();
protected:
//Signal handlers:
void on_button_clicked();
//Child widgets:
Gtk::Button m_button;
Gtk::Box buttonBox;
};
#endif //GTKMM_EXAMPLE_BUTTONS_H
buttons.cc:
#include <iostream>
#include <stdlib.h>
#include "buttons.h"
#include "changeTitle.h"
Buttons::Buttons()
{
m_button.add_pixlabel("info.xpm", "click here");
set_title("Menu");
set_border_width(10);
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&Buttons::on_button_clicked));
add(buttonBox);
buttonBox.pack_start(m_button);
show_all_children();
}
Buttons::~Buttons()
{
}
void Buttons::on_button_clicked()
{
changeTitle();
}
changeTitle.h:
void changeTitle();
changeTitle.cc:
#include "changeTitle.h"
void changeTitle()
{
buttons.set_title("new title");
}