更新函数

时间:2016-03-31 06:06:26

标签: c gtk2

我有一个很大的GTK2代码,其中我遇到了更新整数值的麻烦(在这种情况下是trigan,它在主体中定义并回调给我这个问题的两个函数)。

我打算按下RUN按钮,调用RUN功能,开始实时显示数字。然后,当文本运行时,我将按下STOP按钮调用函数STOP,将trigan的值更新为1.

以下是有问题的代码:

void STOP(GtkWidget *widget, GObject *context_object_stp) 
{

  GtkEntry *trigan = g_object_get_data (context_object_stp, "trigan");


  trigan=1;


}
void RUN(GtkWidget *widget, GObject *context_object) 
{
    GtkEntry *buffer= g_object_get_data (context_object, "buffer");
    GtkEntry *wins = g_object_get_data (context_object, "wins");
    GtkEntry *trigan = g_object_get_data (context_object, "trigan");



    GtkWidget  iter;
    GtkTextIter iterscrll;
    GtkTextMark *mark;

    mark = gtk_text_buffer_get_insert(buffer);
    gtk_text_buffer_get_iter_at_mark(buffer, &iterscrll, mark);



    gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
    trigan=0;
    int i=0;
    int k=0;

    for (i=0; i<90; i=i+1)
    {
     while (trigan==1)
     {

     }
     gchar * stuff = g_strdup_printf("%d"" [%d]\n", i, trigan);
     /* Inserts buffer at position iter. */
     gtk_text_buffer_insert(buffer, &iter, stuff, -1);
     g_free(stuff);

    /* Forcing. */
    while (gtk_events_pending())
    gtk_main_iteration();
    /* Scrolls text_view the minimum distance such that mark is contained within the visible area of the widget. */
    gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(wins), mark);

     for (k=0; k<50000000; k=k+1)
     {
         k++;
     }
     k=0;
    }
}

我的逻辑说这个值为trigan = 1

   while (trigan==1)
     {

     }

应该“停止”RUN功能,但它不会。

请帮忙!

1 个答案:

答案 0 :(得分:0)

是的,您的假设是正确的,但请看一下您的代码摘录:

triga=0;
    int i=0;
    int k=0;

    for (i=0; i<90; i=i+1)
    {
     while (triga==1)
     {

     }

如你所见,定义了triga,指定为0之间从未在while之间进行过操作...所以条件而(triga == 1)是假的......

这就是原因..