我得到的錯誤,因爲gtk_entry它需要字符類型作爲輸入,但我想給它的int類型,所以第一我聲明int類型,然後這個int類型被聲明爲字符類型並給予gtk_entry,但我得到錯誤。我得到的錯誤「警告:初始化使指針從整數沒有投[默認情況下]」
#include<gtk/gtk.h>
void static call(GtkWidget *widget,gpointer data)
{
g_print("\n%s\n",gtk_entry_get_text(GTK_ENTRY(data)));
gint answ=4;
const char* ans=answ; //here is the line having error
gtk_entry_set_text(GTK_ENTRY(data),ans);
gtk_editable_select_region(GTK_EDITABLE(data),0,-1);
}
int main(int agrc, char *agrv[])
{
gtk_init(&agrc,&agrv);
GtkWidget *entry,*window,*button,*hbox;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
hbox=gtk_hbox_new(0,0);
gtk_container_add(GTK_CONTAINER(window),hbox);
button=gtk_button_new_with_mnemonic("write text");
entry=gtk_entry_new();
g_signal_connect(button,"clicked",G_CALLBACK(call),entry);
g_signal_connect(entry,"activate",G_CALLBACK(call),entry);
gtk_box_pack_start(GTK_BOX(hbox),button,0,0,0);
gtk_box_pack_start(GTK_BOX(hbox),entry,0,0,0);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
究竟是什麼,讓你錯誤的行? –
'const char * ans = answ;' – user3132152
同樣,爲什麼要將整數4賦給char?或者是你想要分辨的字符'4'? –