我試圖創建GTK +一個窗口,具有標籤如下所示:錯誤:不被忽略,因爲它應該是空值 - C/GTK +
每當用戶單擊「新建「按鈕,出現一個新選項卡。
然而,當我編譯我的節目,我得到了一個錯誤:空值不被忽略,因爲它應該是
[email protected]:~$ g++ /home/phongcao/C++/GTK+/newtab.cc -o /home/phongcao/C++/GTK+/newtab `pkg-config gtk+-2.0 --cflags --libs`
/home/phongcao/C++/GTK+/newtab.cc: In function ‘int main(int, char**)’:
/home/phongcao/C++/GTK+/newtab.cc:51:3: error: void value not ignored as it ought to be
這裏是代碼:
#include <gtk/gtk.h>
void destroy(GtkWidget *window, gpointer data) {
gtk_main_quit();
}
void new_tab(GtkNotebook *notebook, GtkWidget *content, GtkWidget *hbox) {
gtk_notebook_append_page(notebook, content, hbox);
}
int main(int argc, char *argv[])
{
GtkWidget *window, *label, *content;
GtkWidget *button, *hbox, *notebook;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_window_set_title(GTK_WINDOW(window), "New Tab");
gtk_widget_set_size_request(window, 300, 200);
notebook = gtk_notebook_new();
button = gtk_button_new_with_label("New");
label = gtk_label_new("Tab");
hbox = gtk_hbox_new(FALSE, 5);
content = gtk_label_new("This is a tab");
gint a = 0;
gtk_box_pack_start_defaults(GTK_BOX(hbox), label);
gtk_box_pack_start_defaults(GTK_BOX(hbox), button);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), content, hbox);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
//This following line is where the error is from:
g_signal_connect(G_OBJECT(button), "new_tab", G_CALLBACK(new_tab(GTK_NOTEBOOK(notebook), content, hbox)), NULL);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
gtk_container_add(GTK_CONTAINER(window), notebook);
gtk_widget_show_all(hbox);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
感謝您的幫助!對此,我真的非常感激!!
看起來好像你嘗試使用void函數的返回值。我不能算到53,所以不能說在什麼路線上。 – 2011-04-22 06:30:21
你可以在編譯器抱怨的行上添加註釋嗎?你的例子只有48行:) – hammar 2011-04-22 06:31:32
我已經添加了對錯誤發生的行的評論...對不起,傢伙! – phongvcao 2011-04-22 06:40:35