2013-08-03 61 views
0

我正在寫一個小棋盤遊戲,點擊它後必須添加並在按鈕上顯示圖像,然後調用其他功能以在其他按鈕上顯示圖像,但程序沒有按照我的想法運行,直到所有這些功能完成後才顯示小部件。 這裏是調試:GTK顯示部件

Breakpoint 1, GameControl::button_clicked (widget=0x80dad08, data=0x80563e0) at interface.cc:582 
582 image = gtk_image_new_from_file ("arrow.bmp"); 
(gdb) step 
583 gtk_container_add (GTK_CONTAINER (widget), image); 
(gdb) step 
584 gtk_widget_show (image); 
(gdb) step 
585 computer_move (widget, &control); 
(gdb) step 
GameControl::computer_move (widget=0x80dad08, data=0x80563e0) at interface.cc:520 
520 computer_moving = true; 
(gdb) break interface.cc:586 
Breakpoint 2 at 0x804cdab: file interface.cc, line 586. 
(gdb) continue 
Continuing. 
Breakpoint 2, GameControl::button_clicked (widget=0x80dad08, data=0x80563e0) at interface.cc:586 
586 break; 
(gdb) step 
593 end_dialog(); 
(gdb) next 
595 } 
(gdb) step 
0xb7b1c243 in g_cclosure_marshal_VOID__VOIDv() from /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 
(gdb) step 
Single stepping until exit from function g_cclosure_marshal_VOID__VOIDv,which has no line number information. 
0xb7b33a29 in g_signal_emit_valist() from /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 
(gdb) next 
Single stepping until exit from function g_signal_emit_valist, 
which has no line number information. 
0xb7b34453 in g_signal_emit() from /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 

(gdb) continue 
Continuing. 
[Thread 0xb6b86b40 (LWP 7820) exited] 
[Thread 0xb61ffb40 (LWP 7821) exited] 
[Inferior 1 (process 7817) exited normally] 

直到最後繼續命令被執行時,小部件顯示,對於莫名其妙的窗口小部件沒有顯示,當它去「gtk_widget_show()」,有什麼建議?

回答

2

與大多數GUI工具包一樣,GTK +是事件驅動的。

您應該從您的回調中返回,以便主事件循環(gtk_main())可以處理下一個事件,否則整個程序會凍結。

如果您想通過回調中途處理某些事件,請明確執行。直接從文檔:

/* computation going on */ 

while (gtk_events_pending()) 
    gtk_main_iteration(); 

/* computation continued */ 
+0

哇,非常感謝!它的工作原理,你很棒! – finus