|  | Home · All Classes · Modules

# QDBusArgument Class Reference
[QtDBus module]

The QDBusArgument class is used to marshall and demarshall D-Bus arguments. More...

### Methods

- __init__ (self)
- __init__ (self, QDBusArgument other)
- __init__ (self, object arg, int id = QMetaType.Int)
- add (self, object arg, int id = QMetaType.Int)
- beginArray (self, int id)
- beginMap (self, int kid, int vid)
- beginMapEntry (self)
- beginStructure (self)
- endArray (self)
- endMap (self)
- endMapEntry (self)
- endStructure (self)

## Detailed Description

In C++ the QDBusArgument class is used to marshall and demarshall DBus collection types, i.e. arrays, structures and maps. In PyQt values are de-marshalled automatically and QDBusArgument is only used to marshall values. In C++ marshalling is done using overloaded left shift operators. In PyQt the single add() function is used.

## Method Documentation

### QDBusArgument.__init__ (self)

Constructs an empty QDBusArgument argument.

An empty QDBusArgument object does not allow either reading or writing to be performed.

### QDBusArgument.__init__ (self, QDBusArgument other)

Constructs a copy of the other QDBusArgument object.

Both objects will therefore contain the same state from this point forward. QDBusArguments are explicitly shared and, therefore, any modification to either copy will affect the other one too.

### QDBusArgument.__init__ (self, object arg, int id = QMetaType.Int)

### QDBusArgument.add (self, object arg, int id = QMetaType.Int)

### QDBusArgument.beginArray (self, int id)

Opens a new D-Bus array suitable for appending elements of meta-type id.

This function is used usually in `operator<<` streaming operators, as in the following example:

     // append an array of MyElement types
     QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myarray)
     {
         argument.beginArray( qMetaTypeId<MyElement>() );
         for ( int i = 0; i < myarray.length; ++i )
             argument << myarray.elements[i];
         argument.endArray();
         return argument;
     }

If the type you want to marshall is a QList, QVector or any of the Qt's Container Classes that take one template parameter, you need not declare an `operator<<` function for it, since QtDBus provides generic templates to do the job of marshalling the data. The same applies for STL's sequence containers, such as `std.list`, `std.vector`, etc.

See also endArray(), beginStructure(), and beginMap().

### QDBusArgument.beginMap (self, int kid, int vid)

Opens a new D-Bus map suitable for appending elements. Maps are containers that associate one entry (the key) to another (the value), such as Qt's QMap or QHash. The ids of the map's key and value meta types must be passed in kid and vid respectively.

This function is used usually in `operator<<` streaming operators, as in the following example:

     // append a dictionary that associates ints to MyValue types
     QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &mydict)
     {
         argument.beginMap( QVariant.Int, qMetaTypeId<MyValue>() );
         for ( int i = 0; i < mydict.length; ++i ) {
             argument.beginMapEntry();
             argument << mydict.data[i].key << mydict.data[i].value;
             argument.endMapEntry();
         }
         argument.endMap();
         return argument;
     }

If the type you want to marshall is a QMap or QHash, you need not declare an `operator<<` function for it, since QtDBus provides generic templates to do the job of marshalling the data.

See also endMap(), beginStructure(), beginArray(), and beginMapEntry().

### QDBusArgument.beginMapEntry (self)

Opens a D-Bus map entry suitable for appending the key and value entries. This function is only valid when a map has been opened with beginMap().

See beginMap() for an example of usage of this function.

See also endMapEntry() and beginMap().

### QDBusArgument.beginStructure (self)

Opens a new D-Bus structure suitable for appending new arguments.

This function is used usually in `operator<<` streaming operators, as in the following example:

     QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
     {
         argument.beginStructure();
         argument << mystruct.member1 << mystruct.member2 << ... ;
         argument.endStructure();
         return argument;
     }

Structures can contain other structures, so the following code is also valid:

     QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
     {
         argument.beginStructure();
         argument << mystruct.member1 << mystruct.member2;

         argument.beginStructure();
         argument << mystruct.member3.subMember1 << mystruct.member3.subMember2;
         argument.endStructure();

         argument << mystruct.member4;
         argument.endStructure();
         return argument;
     }

See also endStructure(), beginArray(), and beginMap().

### QDBusArgument.endArray (self)

Closes a D-Bus array opened with beginArray(). This function must be called same number of times that beginArray() is called.

See also beginArray(), endStructure(), and endMap().

### QDBusArgument.endMap (self)

Closes a D-Bus map opened with beginMap(). This function must be called same number of times that beginMap() is called.

See also beginMap(), endStructure(), and endArray().

### QDBusArgument.endMapEntry (self)

Closes a D-Bus map entry opened with beginMapEntry(). This function must be called same number of times that beginMapEntry() is called.

See also beginMapEntry().

### QDBusArgument.endStructure (self)

Closes a D-Bus structure opened with beginStructure(). This function must be called same number of times that beginStructure() is called.

See also beginStructure(), endArray(), and endMap().