Manipulating Label in pure C with GTK3

0

I'm starting now in graphical interfaces and I'm learning about gtk3 using glade to create the screens. The error, which I am going to submit for help, may be more of my oversight over the basics of pointers.

I have a screen that has a "Log" button and a "labelErr" Label, by the time I want it, when I click on the Logar button, the Label text changes to "Hello World" (only for tests). When I put this snippet of code inside the main function, it works without errors and the Label text is changed

GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (builder, "labelErr"));
  // no caso, builder e o construtor da minha janela, e crio um GtkWiget como ponteiro para referenciar meu Label "labelErr"

gtk_label_set_text(GTK_LABEL(widget),"Olá mundo!"); 

When I use this part of the Code in a separate function:

  void Leitura()
 {
 GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (builder, "labelErr"));
gtk_label_set_text(GTK_LABEL(widget),"Olá mundo!"); 
  }

Give the error:

    error: ‘builder’ undeclared (first use in this function); did you mean ‘rindex’?
   GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (builder, "labelErr"));

I think the mistake is because I'm not finding the builder, where am I going wrong? I tried to use the builder as a global variable, but it did not work, anyway it's not the right one, right? On the plus side, how can I pass the builder reference from the main function to the Read function?

The complete code is here:

   #include <gtk/gtk.h> 
   #include "/opt/azulaoServer/headers/Interfaces.h"

  void Leitura();

    int   main ( int   argc ,   char   * argv [ ] ) 
  { 
 GtkBuilder      * builder ;  
 GtkWidget       * window ; 

 gtk_init ( & argc ,   & argv ) ; 

 builder   =   gtk_builder_new ( ) ; 
       //  gtk_builder_add_from_file   ( builder ,   "glade/telaLogin.glade" ,   NULL ) ; 

      GError *err = NULL; 
   if(0 == gtk_builder_add_from_file (builder, "/opt/azulaoServer/glade/telaLogin.glade", &err)) 
  { 
  fprintf(stderr, "Error adding build from file. Error: %s\n", err->message);
   }

         window   =   GTK_WIDGET ( gtk_builder_get_object ( builder ,   "telaLogin" ) ) ; 




  g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);


   //cria o evento, de quando cliquar no x a aplicacao ser fechada


 gtk_builder_connect_signals ( builder ,   NULL ) ; 

 g_object_unref ( builder ) ; 

 gtk_widget_show ( window ) ;                 
 gtk_main ( ) ; 




 return   0 ; 
    } 

     // called when window is closed 
    void   on_window_main_destroy ( ) 
   { 
       gtk_main_quit ( ) ; 
   } 

   void Leitura()
   { 

    GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (builder, "labelErr"));
   gtk_label_set_text(GTK_LABEL(widget),"Olá mundo!"); 
   }
    
asked by anonymous 22.06.2018 / 06:44

0 answers