GTK中用递归实现循环更新button的label

本文介绍了一种使用GTK库实现的定时器方法,该方法适用于进程和线程无法满足需求的场景,例如每300毫秒更新GUI组件的显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个方法是在基于用进程不行,线程又有问题的基础上,而实现的一种可以实现定时执行某个功能的方法。

比如每过300ms 更新个标签等。 

 

static gint

gtk_clock_timer (GtkWidget* button)

{

    gchar time[22];

 

    // if have destroyed all the button then stop the timer

    if(0 == clock_count)

    {

        return TRUE;

    }

 

    get_host_time(time);

    gtk_button_set_label((GtkButton *)button, time);

 

    gtk_timeout_add (CLOCK_DELAY,

                     (GtkFunction) gtk_clock_timer,

                     (gpointer) button);

 

 

    return FALSE;

}

 

static void time_init( GtkWidget** button_p)

{

GtkWidget *button = NULL;

 

button = gtk_button_new();

*button_p = button;

g_signal_connect (GTK_OBJECT (button), "clicked", G_CALLBACK (clicked_cb), NULL);

 

        timer[clock_count] = gtk_timeout_add (CLOCK_DELAY,

                                 (GtkFunction) gtk_clock_timer,

                                 (gpointer) button);

 

gtk_widget_show_all(*button_p);

 

clock_count++;

 

return;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值