Please could anybody helps how to get text from entry.
my App do not throw any error, but do not return any text
I am expecting that app writes to stdout text from entry, when i press button “aktualizuj” to call function:
static void aktualizuj (GtkWidget *widget, gpointer data)
my code:
#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include <string>
#include <iostream>
using namespace std;
static void aktualizuj (GtkWidget *widget, gpointer data) {
cout << "update" << endl;
GtkBuilder *builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "rozlozeni.ui", NULL);
GObject *entry = gtk_builder_get_object (builder, "entry");
string prectenejText = gtk_editable_get_text(GTK_EDITABLE(entry));
cout << "readed text from entry: " << prectenejText << "-*-" << endl;
g_object_unref (builder);
}
static void quit_cb (GtkWindow *window) {
gtk_window_close (window);
}
static void activate (GtkApplication *app, gpointer user_data) {
/* Construct a GtkBuilder instance and load our UI description */
GtkBuilder *builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "rozlozeni.ui", NULL);
cout << "after builder" << endl;
/* Connect signal handlers to the constructed widgets. */
GObject *window = gtk_builder_get_object (builder, "window");
gtk_window_set_application (GTK_WINDOW (window), app);
cout << "after window" << endl;
GObject *button = gtk_builder_get_object (builder, "aktualizuj");
g_signal_connect (button, "clicked", G_CALLBACK (aktualizuj), NULL);
cout << "after button" << endl;
button = gtk_builder_get_object (builder, "ukonci");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (quit_cb), window);
gtk_widget_show (GTK_WIDGET (window));
/* We do not need the builder any more */
g_object_unref (builder);
}
int main (int argc, char *argv[]) {
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
GtkApplication *app = gtk_application_new ("pokusna.testovaci.apka", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
and my rozlozeni.ui file:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkWindow" id="window">
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label">
<property name="label" translatable="1">label</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="1">neco napis</property>
</object>
</child>
<child>
<object class="GtkEntry" id="entry">
<property name="focusable">1</property>
</object>
</child>
<child>
<object class="GtkButton" id="aktualizuj">
<property name="label" translatable="1">aktualizuj</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
</object>
</child>
<child>
<object class="GtkButton" id="ukonci">
<property name="label" translatable="1">ukonci</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
</object>
</child>
</object>
</property>
</object>
</interface>