I listen to "changed" signal of a GtkComboBox. I empty and refill GtkComboBoxText which is a simple variant of GtkComboBox. I'm trying to use a macro g_signal_handlers_block_by_func(instance, func, data) so that the "changed" signal won't be emitted to my callback function while emptying and refilling that box.
I get an error when passing a function as a func: error: ISO C forbids passing argument 6 of ‘g_signal_handlers_block_matched’ between function pointer and ‘void *’ [-Werror=pedantic]
It happens because func is casted to gpointer (typedef to (void*)) in g_signal_handlers_block_matched. As I have understood casting function pointer to data pointer is illegal.
Example:
static void my_callback(GtkComboBox *box, GtkComboBox *other_box)
{
// Some code here
}
g_signal_connect(combo_box, "changed", G_CALLBACK(my_callback), other_box);
// To temporary block changed signals for reaching other_box:
g_signal_handlers_block_by_func(combo_box, G_CALLBACK(my_callback), other_box);
Also tried without G_CALLBACK but it doesn't make a difference. The issue is the same.
How should I use g_signal_handlers_block_by_func?
GObject and GLib require a compiler that "does the right thing" when casting function pointers to void* and vice versa.
From the build code and GLib wiki:
GLib heavily relies on the ability to convert a function pointer to a
void*and back again losslessly. Any platform or compiler which doesn’t support this cannot be used to compile GLib or code which uses GLib. This precludes use of the-pedanticGCC flag with GLib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With