Bruce Bruce - 1 year ago 123
C++ Question

Create a signal with Gtkmm

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();});


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 !

Answer Source
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();});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download