使用Gtkmm创建信号 [英] Create a signal with Gtkmm
本文介绍了使用Gtkmm创建信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将gtkmm库与C ++一起使用,并且试图创建一个允许更改当前选项卡的信号,但它不起作用。
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)
非常感谢您的帮助!
推荐答案
menuit->signal_activate().connect([&bo]() {bo->next_page();});
您通过引用捕获了 bo
,因此,在执行信号时,我想捕获已成为悬挂的引用。
You're capturing bo
by reference, so at the time the signal is executed, I guess the capture became a dangling reference.
尝试复制(毕竟, bo
是一个指针):
Try by copy (after all, bo
is a pointer):
menuit->signal_activate().connect([bo]() {bo->next_page();});
这篇关于使用Gtkmm创建信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文