Signal after finishing entry editing

,

Hello all,
I have in my gtk4 app in C several entries.

I can not find signal which I could use. I want run function editingFinished after I press enter or tab in any entry or after mouse click to another entry.

here is my code:

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

using namespace std;

void editingFinished (GtkWidget* wid, GtkWidget* data) {
    cout << "editingFinished"<< endl;
    cout << "text=" << gtk_editable_get_text(GTK_EDITABLE(data)) << 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 (int i = 0; i < 10; ++i ) {
        entry = gtk_entry_new();
        gtk_box_append (GTK_BOX (vBox), entry);
        if (i>5) {
            text = "text" + to_string(i);
            gtk_editable_set_text(GTK_EDITABLE(entry),text.c_str());
        }
        //g_signal_connect(GTK_EDITABLE(entry), "changed", G_CALLBACK(editingFinished), entry); //emits signal after adding only one char
        //g_signal_connect(GTK_EDITABLE(entry), "insert-text", G_CALLBACK(editingFinished), entry); // notihing happends
        g_signal_connect(GTK_EDITABLE(entry), "editing-done", G_CALLBACK(editingFinished), entry); // notihing happends
    }

    GtkWidget *btn = gtk_button_new_with_label("text in last entry");
    g_signal_connect(GTK_BUTTON(btn), "clicked", G_CALLBACK(editingFinished), entry);
    gtk_box_append  (GTK_BOX (vBox), btn);

    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 ("testing.app", 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;
}
please could anybody advice me which signal or signals solves this issue?
Thank you a lot

I’m not sure if this would work, but it’s possible that the signal notify::has-focus might be useful. It should happen when the has-focus property of the entry changes.

The notify signal is really useful.

thank you for reply!
so I have added into for cycle:

for (int i = 0; i < 10; ++i ) {
        entry = gtk_entry_new();
        gtk_box_append (GTK_BOX (vBox), entry);
        if (i>5) {
            text = "text" + to_string(i);
            gtk_editable_set_text(GTK_EDITABLE(entry),text.c_str());
        }
        //g_signal_connect(GTK_EDITABLE(entry), "changed", G_CALLBACK(editingFinished), entry); //emits signal after adding only one char
        //g_signal_connect(GTK_EDITABLE(entry), "insert-text", G_CALLBACK(editingFinished), entry); // notihing happends
        //g_signal_connect(GTK_EDITABLE(entry), "editing-done", G_CALLBACK(editingFinished), entry); // notihing happends
        g_signal_connect(GTK_WIDGET(entry), "notify::has-focus ", G_CALLBACK(editingFinished), entry);
    }

but it also do nothing. Have I add it right?
thanks

I have found error in my new code.
There is extra space before quotation marks. After deleting space - it works now.
Thanks

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