Question

i'm trying to store an array in a GVariant in order to store it in GSettings.

I'm writing the Application in C using gtk+3 and glib2.

in general an array that contains two elements in each row, which is server name and device name.

so I have the following code:

void tux_gsettings_init() {
     tux_settings = g_settings_new("com.tuxin.TuxMusicStudio");
}

void tux_gsettings_save() {
GVariant *variant;
GVariantBuilder *builder;
builder = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
g_variant_builder_add(builder, "a(ss)", "test1","test2");
g_variant_builder_add(builder, "a(ss)", "testa1","testa2");
variant = g_variant_new("a(ss)", builder);
g_variant_builder_unref(builder);
g_settings_set_value(tux_settings,"audio_devices_in",variant);
}

so i'm trying to store two rows.

I'm getting the following errors:

(tuxmusicstudio:4355): GLib-CRITICAL **: g_variant_builder_end: assertion 'is_valid_builder (builder)' failed

(tuxmusicstudio:4355): GLib-CRITICAL **: g_variant_get_type: assertion 'value != NULL' failed

(tuxmusicstudio:4355): GLib-CRITICAL **: g_variant_type_is_array: assertion 'g_variant_type_check (type)' failed

(tuxmusicstudio:4355): GLib-CRITICAL **: g_variant_get_type_string: assertion 'value != NULL' failed

(tuxmusicstudio:4355): GLib-ERROR **: g_variant_new: expected array GVariantBuilder but the built value has type '(null)'

what am I missing here?

Was it helpful?

Solution

g_variant_builder_add() format string should describe the data you are adding, not the entire array. So something like this should work:

g_variant_builder_add (builder, "(ss)", "test1","test2");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top