C语言 GVariantBuilder build a(ii) or a(vv)



我有这个 2 个 int 的数组,我想通过 dbus 发送。 它总是抱怨值不是元组或空的类型 取决于尝试。哇,它需要看起来像吗?

GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ii)"));
g_variant_builder_add(&builder, "(ii)", 99, 99);
g_variant_builder_add(&builder, "(ii)", 98, 98);
GVariant *value = g_variant_new("a(ii)", &builder);
g_dbus_method_invocation_return_value(invocation, value));
//g_dbus_method_invocation_return_value(invocation, &value)); - also tried
//Previous attempts
//GVariantBuilder *builder; 
// builder = g_variant_builder_new(G_VARIANT_TYPE("a(ii)"));
//g_variant_builder_add(&builder, "(ii)", 99, 99);
//g_variant_builder_add(&builder, "(ii)", 98, 98);
//and
//g_variant_builder_add(builder, "(ii)", 99, 99);
//g_variant_builder_add(builder, "(ii)", 98, 98);
GVariantBuilder

并不意味着用作GVariant的有效载荷:它是一个构建器模式对象,它将根据其内容构造GVariant

GVariantBuilder builder;
// Initialize the GVariantBuilder with the final type
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ii)"));
// Add the contents of the variant
g_variant_builder_add (&builder, "(ii)", 99, 99);
g_variant_builder_add (&builder, "(ii)", 98, 98);
// Construct the variant from the builder
GVariant *v = g_variant_builder_end (&builder);

有关详细信息,请参阅g_variant_builder_init()g_variant_builder_end()的文档。

相关内容

  • 没有找到相关文章

最新更新