Create a signal with Gtkmm

别说谁变了你拦得住时间么 提交于 2019-12-25 04:24:11

问题


I am using the gtkmm library with C++, and I am trying to create a signal which allows to change current tab, but it does not work.

Actually I think the problem comes from this line:

menuit->signal_activate().connect([&bo]() {bo->next_page();}); 

Where:

menuit = Gtk::MenuItem
bo = Gtk::Notebook

The code compiles well, but when executing I get this line :

Segmentation fault
(program exited with code: 139)

Thank you a lot for your help !


回答1:


menuit->signal_activate().connect([&bo]() {bo->next_page();});

You're capturing bo by reference, so at the time the signal is executed, I guess the capture became a dangling reference.

Try by copy (after all, bo is a pointer):

menuit->signal_activate().connect([bo]() {bo->next_page();});


来源:https://stackoverflow.com/questions/40822089/create-a-signal-with-gtkmm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!