Marshalling of the Structure and array of Structures from QT into GLib API

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Nov 28 03:52:11 PST 2011


First, the obligatory note about dbus-glib: since GLib 2.26, the GIO library
packaged as part of GLib contains a D-Bus implementation (GDBus) of
considerably higher quality than dbus-glib. I recommend using GDBus instead.

Further comments below.

On Mon, 28 Nov 2011 at 12:15:13 +0100, Bogdan Lotko wrote:
> From the Qt Side the procedure is the same, pack the list into
> QVariant and send.
[...]
> BUT  What I receive on the GLib API is not the GValueArray * but the
> GPtrArray * is it correct?

Don't think of it as Qt <-> dbus-glib. Instead, think of it as a two-stage
process, which is what actually happens:

    Qt <-> D-Bus               D-Bus <-> dbus-glib.

D-Bus has its own type system, and without understanding what's happening
in the middle, it's hard to understand what happens at the other end.
The GVariant type system in GLib 2.26 is the same as the D-Bus type system,
except that D-Bus doesn't have "maybe" types like "mi", or empty structs, "()".

Here you seem to be doing:

    Qt QList<some struct> ->
         D-Bus a(something) ->
             dbus-glib GPtrArray<some GValueArray>

(C doesn't have templates, obviously, but when dealing with dbus-glib it's
often useful to use a pseudo-C++ notation to say things like "GPtrArray
where each element is a GValueArray".)

> It is somehow misleading. I thought, that packing of an item into
> QVariant, will always result in a GValueArray * on GLib API.

No, it'll only result in a GValueArray if the D-Bus type is a struct
(represented by parentheses, "(...)", in a D-Bus type signature). You're 
now sending an array of structs, "a(...)" in D-Bus terminology. This is
an array in which each element is a struct.

(D-Bus makes no distinction between the concept of an array and a list -
they're both "array" in a D-Bus message.)

> Additionally for the method generated from the XML definition
> 
> <method name="myMethod">
> <arg type="a(myStructureSignature)">
> </method>
> 
> the compiler accepts both types of argument i.e. GValueArray * but
> the GPtrArray * could somebody explain why?

My guess is: either one of them gives you a warning which you haven't noticed
(C compilers will allow all sorts of rubbish by default), or the method you're
using has varargs so the compiler has no idea what type you're meant to
have used.

    S


More information about the dbus mailing list