QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1119|回复: 4

请教如何在GTK中使用线程

[复制链接]
发表于 2005-12-19 10:46:33 | 显示全部楼层 |阅读模式
因为没找到相关资料,请高手指点:
包括应该加哪个头文件、使用哪些线程函数、编译时需要添加哪些选项。
谢谢。
发表于 2005-12-19 12:23:33 | 显示全部楼层
gtk_init()之前加上
[code:1]
    g_thread_init(NULL);
#if GTK_MAJOR_VERSION == 2
    gdk_threads_init();
#endif
[/code:1]

gtk_main()之前要加上gdk_threads_enter();,之后要加上gdk_threads_leave();
[code:1]
    gdk_threads_enter();
    gtk_main();
    gdk_threads_leave();
[/code:1]

在线程里对控件进行操作时也要用gdk_threads_enter();和gdk_threads_leave();

比如:
[code:1]
gdk_threads_enter();
gtk_widget_set_usize(label,100,100);
gtk_label_set_text(label,"hello world");
gdk_threads_leave();
[/code:1]

编译时加上-lpthread -lgthread
gtk2是:-lpthread -lgthread-2.0
回复

使用道具 举报

 楼主| 发表于 2005-12-20 15:11:22 | 显示全部楼层
多谢指教!

另外,下面这个函数到底是干什麽的,看了半天注释也没领会意思:
gtk_toggle_button_set_inconsistent ()

void        gtk_toggle_button_set_inconsistent
                                            (GtkToggleButton *toggle_button,
                                             gboolean setting);

If the user has selected a range of elements (such as some text or spreadsheet cells) that are affected by a toggle button, and the current values in that range are inconsistent, you may want to display the toggle in an "in between" state. This function turns on "in between" display. Normally you would turn off the inconsistent state again if the user toggles the toggle button. This has to be done manually, gtk_toggle_button_set_inconsistent() only affects visual appearance, it doesn't affect the semantics of the button.
回复

使用道具 举报

发表于 2005-12-20 18:25:55 | 显示全部楼层
不知道
回复

使用道具 举报

发表于 2005-12-25 10:49:03 | 显示全部楼层
学习...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-9 07:04 , Processed in 0.063726 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表