GTK3: How to add accessibility relation

Hello, I’m a newbie to GTK and C++, and I’m trying to add accessibility relations to GParted. (I’ve already used GTK before, but only with Glade and Rust bindings)

Precisely, here I want to add a relation between a Gtk::Label and an OptionComboBox: Gtk::ComboBox.

I tried this:

atk_object_add_relationship(
    atk_gobject_accessible_for_object((GObject*) label), // label is Gtk::Label*
    ATK_RELATION_LABEL_FOR,
    atk_gobject_accessible_for_object((GObject) combo_type)); // combo_type is a class child of Gtk::ComboBox

It compiles, but there is a runtime error, and it does not work:

(gpartedbin:18126): Atk-CRITICAL **: 10:48:35.604: atk_gobject_accessible_for_object: assertion 'G_IS_OBJECT (obj)' failed

(gpartedbin:18126): Atk-CRITICAL **: 10:48:35.604: atk_gobject_accessible_for_object: assertion 'G_IS_OBJECT (obj)' failed

(gpartedbin:18126): Atk-CRITICAL **: 10:48:35.604: atk_object_add_relationship: assertion 'ATK_IS_OBJECT (object)' failed

Unfortunately I do not see any other way to instantiate Atk::Object, which is needed to add relations.

How can I do this correctly? Thanks.

To get the accessible object for a GtkWidget in GTK3 you need to call gtk_widget_get_accessible(): Gtk.Widget.get_accessible

1 Like

To get the underlying pointer from a gtkmm wrapper you use .gobj(), C-style casts - esp (GObject) - are fairly nonsensical here

1 Like

Thank you, this simple line works:

combo_type.get_accessible()->add_relationship(Atk::RELATION_LABELLED_BY, label->get_accessible());
1 Like

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