GTK显示小部件

时间:2013-08-03 03:45:03

标签: c++ gdb gtk

我正在编写一个小桌面游戏,必须在点击它后添加并在按钮上显示图像,然后回调一些其他功能以在其他按钮上显示图像,但程序没有像我一样运行我想,在完成所有这些功能之前,小部件才会显示。 这是debug:

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()”,有什么建议吗?

1 个答案:

答案 0 :(得分:2)

与大多数GUI工具包一样,GTK +是事件驱动的。

你应该从你的回调中返回,所以主事件循环(gtk_main())可以处理下一个事件,否则整个程序就会冻结。

如果你想在回调中途处理一些事件,你可以明确地这样做。直接来自文档:

/* computation going on */

while (gtk_events_pending ())
    gtk_main_iteration ();

/* computation continued */