C ++,将g_signal_connect事件正确添加到按钮

时间:2014-04-10 07:54:54

标签: c++ gtk

我使用gtk创建了一个窗口。然后我想在按钮上添加点击事件。我尝试了几种方法但没有成功

#if GTK_CHECK_VERSION(3,0,0)
    GtkBuilder* builder = newDialogBuilder("smartart.ui");
#else
    GtkBuilder* builder = newDialogBuilder("smartart-2.ui");
#endif
window = GTK_WIDGET(gtk_builder_get_object(builder, "smartartDlg"));
spin = GTK_WIDGET(gtk_builder_get_object(builder, "summarySpin"));
m_btOk=GTK_WIDGET(gtk_builder_get_object(builder, "btOk"));
m_btClose=GTK_WIDGET(gtk_builder_get_object(builder, "btClose"));

然后我尝试使用下面的代码添加信号

 g_signal_connect (GTK_DIALOG (m_btClose), "response",G_CALLBACK(Smartart__onCloseClicked),NUll);

然后编译但是给出了运行时错误

我的Smartart__onCloseClicked方法位于

之下
void
Smartart__onCloseClicked (GtkButton * /*button*/,gpointer   data)
{
    fprintf(stderr, "Close button clicked");
}

1 个答案:

答案 0 :(得分:2)

GtkButton点击的正确事件应为clicked

g_signal_connect (G_OBJECT (m_btClose), "clicked",G_CALLBACK(Smartart__onCloseClicked),NULL);

参考:GtkButton reference