我试图在GTK 2+中做一个下拉菜单,我得出的结论是他们被称为" gtk_combo_box"。但是,每当我尝试编译时,它都会让我在函数错误中缺少参数......
以下是重要的代码部分:
vbox3_field = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (hbox2), vbox3_field);
gtk_box_pack_start (GTK_BOX (hbox2), vbox3_field, FALSE, TRUE, 0);
vbox3_sett = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (hbox2), vbox3_sett);
ball_menu=gtk_combo_box_text_new ();
gtk_combo_box_text_append_text (GtkComboBoxText ball_menu, "1");
gtk_combo_box_text_append_text (GtkComboBoxText ball_menu, "2");
gtk_combo_box_set_active (GtkComboBox *combo_box, 0);
//g_signal_connect (ball_menu, "changed", G_CALLBACK (cb_ball_selection), gtk_combo_box_text_get_active_text ());
gtk_box_pack_start(GTK_BOX (vbox3_sett), ball_menu);
当我尝试使用" GtkComboBoxText"在函数参数之外,它仍然给出了一个警告,指出不兼容的指针类型。 (我宣布" ball_menu"作为GtkWidget * ball_menu)。
该功能在GTK 2+参考站点中定义如下:
void
gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
const gchar *text);
以下是编译结果:
gcc -o main main.c `pkg-config --cflags --libs gtk+-2.0` -lm
main.c: In function ‘main’:
main.c:265:35: error: expected expression before ‘GtkComboBox’
gtk_combo_box_text_append_text (GtkComboBoxText ball_menu, "1");
^
main.c:265:35: error: too few arguments to function ‘gtk_combo_box_text_append_text’
In file included from /usr/include/gtk-2.0/gtk/gtk.h:74:0,
from main.c:1:
/usr/include/gtk-2.0/gtk/gtkcomboboxtext.h:63:15: note: declared here
void gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
^
main.c:266:35: error: expected expression before ‘GtkComboBoxText’
gtk_combo_box_text_append_text (GtkComboBoxText ball_menu, "2");
^
main.c:266:35: error: too few arguments to function ‘gtk_combo_box_text_append_text’
In file included from /usr/include/gtk-2.0/gtk/gtk.h:74:0,
from main.c:1:
/usr/include/gtk-2.0/gtk/gtkcomboboxtext.h:63:15: note: declared here
void gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
^
main.c:267:29: error: expected expression before ‘GtkComboBox’
gtk_combo_box_set_active (GtkComboBox *combo_box, 0);
^
main.c:267:29: error: too few arguments to function ‘gtk_combo_box_set_active’
In file included from /usr/include/gtk-2.0/gtk/gtk.h:72:0,
from main.c:1:
/usr/include/gtk-2.0/gtk/gtkcombobox.h:101:15: note: declared here
void gtk_combo_box_set_active (GtkComboBox *combo_box,
^
有谁知道发生这种情况的原因?
答案 0 :(得分:4)
gtk_combo_box_text_append_text (GtkComboBoxText ball_menu, "1");
没有有效的演员/转化,请改为
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(ball_menu), "1");