Want to use g_timeout_add. Have to run a glib main

2019-07-19 15:19发布

I am trying to add a callback using g_timeout_add ( timevalue , Func, values passed in Func) to get some status or print something after timevalue.

I am not able to see it. Do I have to call a main loop also? OR any other type of function to get it working ?

2条回答
姐就是有狂的资本
2楼-- · 2019-07-19 15:55

Yes, you need a main-loop as well. This can be either implicit (e.g. in a gtk+ app it's created for you), or explicitly (use g_main_loop_new and g_main_loop_run), ie:

loop = g_main_loop_new (NULL, TRUE)

g_timeout_add ( ... )

g_main_loop_run (loop)

...
查看更多
\"骚年 ilove
3楼-- · 2019-07-19 16:01

g_timeout_add is a wrapper for creating a GSouce which will be used/worked on in the mainloop. So commonly a GMainLoop is run, or in more complex cases, g_main_loop_iteration (or similar) is called in a loop.

查看更多
登录 后发表回答