Focus_out_event for Entry in gtkmm-4.8

Hello community,

I use signal_focus_out_event in gtkmm-3 to validate user input in Entry.

In gtkmm-4.8 on Ubuntu 22.10, it does not compile. How can I validate Entry input then?

The 4.0.1 tutorial mentioned focus_out in both Entry and ComboBox sections.

  m_entry1.signal_focus_out_event().connect( // Err
        sigc::mem_fun(*this, &MyWindow::on_entry_focus_out_event));

        sigc::mem_fun(*this, &MyWindow::on_button_clicked));
$ make
g++ `pkg-config gtkmm-4.0 --cflags` -c -o main.o main.cpp
g++ `pkg-config gtkmm-4.0 --cflags` -c -o helloworld.o helloworld.cpp
helloworld.cpp: In constructor ‘MyWindow::MyWindow()’:
helloworld.cpp:21:12: error: ‘class Gtk::Entry’ has no member named ‘signal_focus_out_event’
   21 |   m_entry1.signal_focus_out_event().connect(
      |            ^~~~~~~~~~~~~~~~~~~~~~
make: *** [<builtin>: helloworld.o] Error 1

$ apt show libgtkmm-4.0-dev
Version: 4.8.0-2

There is no such signal in GtkWidget any more; the migration guide for GTK4 has list of replacements.

If you want to track key focus on a widget in GTK4 you will need to use GtkEventControllerFocus object.

1 Like

Thanks ebassi,

I followed EventControllerFocus example here
My example works now.

1 Like

Hi ebassi,

I read the example code of connecting signal leave with widgets ComboBox, ComboBoxText. The example calls disconnect() manually to avoid calling signal handler during ComboBox being destructed.

Does this apply to all widgets connecting to signal leave, eg. Entry, …

I suppose you mean the combobox/entry_complex and
combobox/entry_text examples.

Signals that are emitted while an object with a signal handler is being deleted can
be a problem. See also issue gtkmm#128,
where a program crashes when a signal handler for Gtk::SpinButton::signal_value_changed()
is called during destruction.

I can’t say for sure that the leave signal will be a problem for you. If you
want to be on the safe side, I recommend that you disconnect the signal handler
in the destructor of the object with the signal handler, like in the ComboBox examples.

1 Like

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