Gtk4 C - catch signal after entry finishing edit


I need again help with gtk4 app written in c.

I need enter into function editingFinished after finishing edit in gtk_entry (after pressing tab or mouse clicking into other).

I have tested use notify::focus-out-event, but it does nothing.

Pleace could anybody help me how to improve my code.

#include <gtk/gtk.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int cnt = 0;

void editingFinished (GtkWidget* wid, GtkWidget* data) {
    cout << "editingFinished"<< endl;
    string text = gtk_editable_get_text(GTK_EDITABLE(wid));
    cout <<to_string(cnt) << text << endl;

static void appActivate (GApplication *app, gpointer user_data) {
    GtkWidget *win = gtk_application_window_new (GTK_APPLICATION (app));
    gtk_window_set_title (GTK_WINDOW (win), "Title");
    gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);

    GtkWidget  *vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,10);

    gtk_window_set_child (GTK_WINDOW (win), vBox);

    GtkWidget *labText = gtk_label_new("label");
    gtk_box_append (GTK_BOX (vBox), labText);

    GtkWidget *entry;
    string text;
    for (unsigned int i = 0; i < 2; ++i ) {
        entry = gtk_entry_new();
        gtk_box_append (GTK_BOX (vBox), entry);
        if (i == 0)
        //g_signal_connect(GTK_WIDGET(entry), "notify::has-focus", G_CALLBACK(editingFinished), NULL);
        //g_signal_connect(GTK_WIDGET(entry), "changed", G_CALLBACK(editingFinished), NULL); - tohle funguje i kdyz pridam pismenko
        g_signal_connect(G_OBJECT(entry), "notify::focus-out-event", G_CALLBACK(editingFinished), NULL);

    GtkWidget *btnBack = gtk_button_new_with_label("Close");
    gtk_box_append  (GTK_BOX (vBox), btnBack);
    g_signal_connect_swapped(GTK_BUTTON(btnBack), "clicked", G_CALLBACK(gtk_window_destroy), win);

    gtk_widget_show (win);

int main(int argc, char **argv) {
    GtkApplication *app;
    app = gtk_application_new ("", G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "activate", G_CALLBACK (appActivate), NULL);
    return g_application_run (G_APPLICATION (app), NULL, NULL);
    g_object_unref (app);

    return 0;

type or paste code here

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.