これに似た質問がありますが、私の質問には答えません。GTKMM を使用して GUI を作成しています。ボタンのコールバックで単一の文字を渡そうとしています。
この文字は、グローバル変数に割り当てられますletter
。しかし、私はポインターを理解していないので、これをかなり長い間機能させようとしてきましたが、成功しませんでした。
main.cpp
#include <gtkmm.h>
#include "window.h"
int main(int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "com.gtkmm.tutorial3.base");
mywindow window;
return app->run(window);
}
ウィンドウ.cpp
#include "window.h"
mywindow::mywindow()
{
set_default_size(480, 320);
set_title("Transfer");
Gtk::Box *vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0));
add(*vbox);
Gtk::Grid *grid = Gtk::manage(new Gtk::Grid);
grid->set_border_width(10);
vbox->add(*grid);
Gtk::Button *a = Gtk::manage(new Gtk::Button("A"));
//a->set_hexpand(true);
//a->set_vexpand(true);//%%%%%%%% next line is the issue%%%%%%%%%
a->signal_clicked().connect(sigc::mem_fun(*this, &mywindow::on_click('a')));
grid->attach(*a, 0, 0, 1, 1);//x=0,y=0, span 1 wide, and 1 tall
Gtk::Button *b = Gtk::manage(new Gtk::Button("B"));
//b->set_hexpand(true);
//b->set_vexpand(true);
b->signal_clicked().connect(sigc::mem_fun(*this, &mywindow::on_click('b')));
grid->attach(*b, 1, 0, 1, 1);
Gtk::Button *c = Gtk::manage(new Gtk::Button("C"));
//c->set_hexpand(true);
//c->set_vexpand(true);
c->signal_clicked().connect(sigc::mem_fun(*this, &mywindow::on_click('c')));
grid->attach(*c, 2, 0, 1, 1);
vbox->show_all();
}
mywindow::~mywindow()
{
//dtor
}
void mywindow::on_click(char l)
{
letter = l;
}
window.h
#ifndef MYWINDOW_H
#define MYWINDOW_H
#include <gtkmm.h>
class mywindow : public Gtk::Window
{
public:
mywindow();
virtual ~mywindow();
protected:
char letter;//global variable where the letter is stored
char on_click(char l);
private:
};
#endif // MYWINDOW_H
これを に置き換えたり*
pointer
、&
その逆を行ったりしmywindow
ましたが、うまく機能せず、どうすればよいかわかりません。