Enviado em 25/04/2015 - 12:54h
Boa tarde, estou estutando gtk+ com o glade, e o programa que eu fis aparece a janela, mas nao conecta as funcoes callback.
#include <glade/glade.h> // Carrega os recursos do Glade
#include <gtk/gtk.h>
//Carrega os recursos do GTK
GladeXML * xml; //Cria um ponteiro para uma estrutura GladeXML
void fechar() //Fechar a aplicação
{
gtk_main_quit(); //Encerra o loop principal do GTK
}
void aplicar() //Exibe a mensagem definida
{
GtkWidget * mensagem; // Cria um ponteiro para o widget
mensagem = glade_xml_get_widget(xml,"label1"); //Associa owidget ao ponteiro
gtk_label_set_text(GTK_LABEL(mensagem),"Olá mundo!"); //Define otexto que será exibido no widget
}
void limpar()
{
GtkWidget * mensagem;
mensagem = glade_xml_get_widget(xml,"label1");
gtk_label_set_text(GTK_LABEL(mensagem),"");
}
int main(int argc,char *argv[])
//O Corpo principal do Programa
{
GtkWidget *window;
gtk_init(&argc,&argv);
//glade_init();
//Inicializa o GTK
//Inicializa o Glade – Isto geralmente é opcional
xml = glade_xml_new("hello.glade",NULL,NULL); //Lê o arquivo com aestrutura XML da sua aplicação
glade_xml_signal_autoconnect(xml); //Conecta todos os sinais aos seus manipuladores
window = glade_xml_get_widget(xml, "window1");
gtk_widget_show_all(window);
gtk_main(); // O Loop de eventos do GTK
return 0;
}
<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
<!-- interface-requires gtk+ 2.24 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Hello World</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<signal name="destroy" handler="gtk_main_quit"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">[Apagar]</property>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkButton" id="button1">
<property name="label" translatable="yes">Aplicar</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="aplicar"/>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button2">
<property name="label" translatable="yes">Limpar</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="limpar"/>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button3">
<property name="label" translatable="yes">Sair</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="fechar"/>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>