I am confused about GList and so ask help from you!



Sir,

My program code is as follow:

gint f_changenode(GtkWidget *widget, gpointer data)

{

         GtkWidget *windowdlg;

         GtkWidget *vbox, *combo;

         GList *list = NULL;

         gint b[4] = {0xabcd, 0xadaa, 0x12da, 0x3212}, i = 0;

         gchar d[10];

         gpointer p = (gpointer) &d[0];

        

         windowdlg = gtk_window_new(GTK_WINDOW_TOPLEVEL);

         g_signal_connect(G_OBJECT(windowdlg), "destroy",

                   G_CALLBACK(f_ChangeNodeDlg), NULL);

         gtk_window_set_position(GTK_WINDOW(windowdlg), GTK_WIN_POS_CENTER);

         gtk_window_set_default_size(GTK_WINDOW(windowdlg), 300, 100);

        

         vbox = gtk_vbox_new(FALSE, 0);

         gtk_widget_show(vbox);

        

         /*

         list = g_list_append(list, "abcd");

         list = g_list_append(list, "adaa");

         list = g_list_append(list, "12da");

         list = g_list_append(list, "3212");

         for(i = 0; i < 4; i++)

         {

                   snprintf(d, 10, "%04X", 0xffff & b[i]);

                   g_print("string%d is %04X but d[] is %s\n", i, 0xffff&b[i], d);

                   list = g_list_append(list, d);

         }*/

        

                   snprintf(d, 10, "%04X", 0xffff & b[0]);

                   g_print("string%d is %04X but d[] is %s\n", 0, 0xffff&b[0], d);

                   list = g_list_append(list, d);

 

                   snprintf(d, 10, "%04X", 0xffff & b[1]);

                   g_print("string%d is %04X but d[] is %s\n", 1, 0xffff&b[1], d);

                   list = g_list_append(list, d);

                  

                   snprintf(d, 10, "%04X", 0xffff & b[2]);

                   g_print("string%d is %04X but d[] is %s\n", 2, 0xffff&b[2], d);

                   list = g_list_append(list, d);

        

         combo = gtk_combo_new();

         gtk_combo_set_popdown_strings(GTK_COMBO(combo), list);

         gtk_widget_show(combo);

        

         gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);

        

         gtk_container_add(GTK_CONTAINER(windowdlg), vbox);

        

                  

        

         gtk_widget_show(windowdlg);

         snprintf(gcharbuffer, 100, "changenode\n");

         addmsg2textview(gcharbuffer, FALSE);

         g_print("changenode\n");

         return 0;

}

When I add a new string to list. No error happened, but at last, all the data is the same, and picture is as follow

此邮件来自: 桂高杰

Tel: 13704813937

E-mail: guigaojie1984 163 com

QQ: 276032923

 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]