如何使用g_timeout_add? [英] How to use g_timeout_add?

查看:365
本文介绍了如何使用g_timeout_add?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用GTK和Glade用C编写一个用于串行通信的程序.我在使用g_timeout_add时遇到问题.例如,我有一个函数serial_data(),其中包含我的串行数据,而我有一个按钮处理程序on_update_button_clicked().因此,到目前为止,如果单击update button,则应该运行gtk_timeout.但是它只运行了一次.

I am making a program in C with GTK and Glade for a serial communication. I am having problem using g_timeout_add. For example I have a function serial_data() which contain my serial data and I have a button handler on_update_button_clicked(). So till now I have done that if update button is clicked, gtk_timeout should run. But it running just for one time.

on_update_button_clicked(GtkButton *Update_Button)
{
     //2nd argument is serial_data function which contain actual data    
     g_timeout_add(250,serial_data,NULL); 
}

我错过了重点吗?

我还有另一个按钮stop button.因此,我希望在单击stop button handlertimeout应该停止.怎么做.?

I have another button stop button. So i want that timeout should stop when stop button handler is clicked. How to do that.??

还有一个问题要问,我想计算timeout像计数器一样运行的次数.这样我就可以显示计数器的数量.这怎么可能.? 请帮助谢谢.

One more question to ask, I want to count the number of times timeout is running like a counter. So that I can display the numbers of counter. How is this possible.? Please help thanks.

推荐答案

g_timeout_add()返回应存储的事件源ID.您可以在停止按钮处理程序中使用具有该ID的g_source_remove()来停止超时.

g_timeout_add() returns an event source id that you should store. You can use g_source_remove() with that id in your stop button handler to stop the timeout.

这篇关于如何使用g_timeout_add?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆