QDBusArgument Class Reference

[ QtDBus module]

The QDBusArgument class is used to marshall and demarshall D-Bus 自变量。 更多...

方法


详细描述

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.


方法文档编制

QDBusArgument.__init__ ( self )

构造空 QDBusArgument 自变量。

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

QDBusArgument.__init__ ( self , QDBusArgument   other )

构造副本为 other QDBusArgument 对象。

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 容器类 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.

另请参阅 endArray (), beginStructure (),和 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 分别。

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.

另请参阅 endMap (), beginStructure (), beginArray (),和 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 ().

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

另请参阅 endMapEntry () 和 beginMap ().

QDBusArgument.beginStructure ( self )

Opens a new D-Bus structure suitable for appending new 自变量。

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;
 }
			

另请参阅 endStructure (), beginArray (),和 beginMap ().

QDBusArgument.endArray ( self )

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

另请参阅 beginArray (), endStructure (),和 endMap ().

QDBusArgument.endMap ( self )

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

另请参阅 beginMap (), endStructure (),和 endArray ().

QDBusArgument.endMapEntry ( self )

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

另请参阅 beginMapEntry ().

QDBusArgument.endStructure ( self )

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

另请参阅 beginStructure (), endArray (),和 endMap ().