我使用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");
}
答案 0 :(得分:2)
GtkButton点击的正确事件应为clicked
。
g_signal_connect (G_OBJECT (m_btClose), "clicked",G_CALLBACK(Smartart__onCloseClicked),NULL);