方法

GLibVariantBuilderopen

自:2.24

声明 [源]

void
g_variant_builder_open (
  GVariantBuilder* builder,
  const GVariantType* type
)

描述 [源]

在给定的builder内部打开一个子容器。当向子容器添加完项目后,必须调用g_variant_builder_close()type是容器的类型:因此要构建一个包含多个值的元组,type必须包括元组本身。

以任何方式调用此函数构建不一致的值(例如:添加过多的值或类型不正确的值)是错误的。

构建嵌套变体的示例

GVariantBuilder builder;
guint32 some_number = get_number ();
g_autoptr (GHashTable) some_dict = get_dict ();
GHashTableIter iter;
const gchar *key;
const GVariant *value;
g_autoptr (GVariant) output = NULL;

g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ua{sv})"));
g_variant_builder_add (&builder, "u", some_number);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));

g_hash_table_iter_init (&iter, some_dict);
while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
  {
    g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
    g_variant_builder_add (&builder, "s", key);
    g_variant_builder_add (&builder, "v", value);
    g_variant_builder_close (&builder);
  }

g_variant_builder_close (&builder);

output = g_variant_builder_end (&builder);

自:2.24

参数

type

类型: GVariantType

容器的GVariantType

数据由该方法调用者所有。