I have a small problem, I have used GTK with other languages but with C being new I cannot find tutorials that allow me to use interfaces created with Glade and the ones I have found explain everything else.
I tried to write a code in C where I have to insert a text in a GTK_ENTRY but nothing appears even following the instructions and using alternatives errors are shown during compilation.
I need to use GLADE because the software will have to work in many languages and the Glade file is customizable.
gtk_entry.cpp
#include <stdio.h>
#include <gtk/gtk.h>
#include <gmodule.h>
GtkWidget *MyEntry;
int main (int argc, char *argv[]){
GtkBuilder *XML;
GtkWidget *window;
gtk_init(&argc, &argv);
XML = gtk_builder_new();
gtk_builder_add_from_file (XML, "gtk_entry.glade", NULL);
window = GTK_WIDGET(gtk_builder_get_object(XML, "MyWindow"));
MyEntry = GTK_WIDGET(gtk_builder_get_object(XML, "MyEntry"));
gtk_builder_connect_signals(XML, NULL);
g_object_unref(XML);
gtk_widget_show(window);
gtk_main();
return 0;
}
extern "C" G_MODULE_EXPORT void on_Write_clicked(GtkButton *Write, gpointer user_data)
{
const gchar *TextVar;
printf("\n Verify Button Write");//Its work correctly
TextVar = "Verify Button Write"; // Work too
//doesnt appar nothing
void gtk_entry_set_text (GtkEntry* MyEntry, const gchar *TextVar);
}
extern "C" G_MODULE_EXPORT void on_Exit_clicked(GtkButton *Exit, gpointer user_data)
{
gtk_main_quit();
}
extern "C" G_MODULE_EXPORT void on_MyWindow_destroy(GtkWidget *MyWindow, gpointer user_data)
{
gtk_main_quit();
}
gtk_entry.glade
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk " version="3.24"/>
<object id="MyWindow">
<property name="can-focus">False</property>
<signal name="destroy" handler="on_MyWindow_destroy" swapped="no"/>
<child>
<object >
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object id="MyEntry">
<property name="width-request">100</property>
<property name="height-request">39</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="x">56</property>
<property name="y">38</property>
</packing>
</child>
<child>
<object id="Write">
<property name="label" translatable="yes">Write Text</property>
<property name="width-request">100</property>
<property name="height-request">80</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_Write_clicked" swapped="no"/>
</object>
<packing>
<property name="x">60</property>
<property name="y">100</property>
</packing>
</child>
<child>
<object id="Exit">
<property name="label" translatable="yes">Exit</property>
<property name="width-request">100</property>
<property name="height-request">80</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_Exit_clicked" swapped="no"/>
</object>
<packing>
<property name="x">200</property>
<property name="y">100</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
CodePudding user response:
Change the following line
//doesnt appar nothing
void gtk_entry_set_text (GtkEntry* MyEntry, const gchar *TextVar);
with
gtk_entry_set_text(GTK_ENTRY(MyEntry), TextVar);
And make sure you are compiling with -rdynamic
flag.