Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1062434
  • 博文数量: 264
  • 博客积分: 6005
  • 博客等级: 大校
  • 技术积分: 2798
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 20:15
文章分类

全部博文(264)

文章存档

2011年(42)

2010年(213)

2009年(4)

2008年(2)

2007年(3)

分类: C/C++

2010-10-16 10:55:26

QDeclarativePropertyMap Class Reference

The QDeclarativePropertyMap class allows you to set key-value pairs that can be used in QML bindings. More...

 #include <QDeclarativePropertyMap>

Inherits QObject.

This class was introduced in Qt 4.7.

    List of all members, including inherited members

Public Functions
    QDeclarativePropertyMap ( QObject * parent = 0 )
virtual     ~QDeclarativePropertyMap ()
void     clear ( const QString & key )
bool     contains ( const QString & key ) const
int     count () const
void     insert ( const QString & key, const QVariant & value )
bool     isEmpty () const
int     size () const
QVariant     value ( const QString & key ) const
QVariant &     operator[] ( const QString & key )
QVariant     operator[] ( const QString & key ) const

    29 public functions inherited from QObject

Signals
void     valueChanged ( const QString & key, const QVariant & value )

    1 signal inherited from QObject

Additional Inherited Members

    1 property inherited from QObject
    1 public slot inherited from QObject
    5 static public members inherited from QObject
    7 protected functions inherited from QObject

Detailed Description

The QDeclarativePropertyMap class allows you to set key-value pairs that can be used in QML bindings.

QDeclarativePropertyMap provides a convenient way to expose domain data to the UI layer. The following example shows how you might declare data in C++ and then access it in QML.

In the C++ file:

 // create our data

 QDeclarativePropertyMap ownerData;
 ownerData.insert("name", QVariant(QString("John Smith")));
 ownerData.insert("phone", QVariant(QString("555-5555")));

 // expose it to the UI layer

 QDeclarativeView view;
 QDeclarativeContext *ctxt = view.rootContext();
 ctxt->setContextProperty("owner", &ownerData);

 view.setSource(QUrl::fromLocalFile("main.qml"));
 view.show();

Then, in main.qml:

 Text { text: owner.name + " " + owner.phone }

The binding is dynamic - whenever a key's value is updated, anything bound to that key will be updated as well.

To detect value changes made in the UI layer you can connect to the valueChanged() signal. However, note that valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

Note: It is not possible to remove keys from the map; once a key has been added, you can only modify or clear its associated value.
Member Function Documentation
QDeclarativePropertyMap::QDeclarativePropertyMap ( QObject * parent = 0 )

Constructs a bindable map with parent object parent.
QDeclarativePropertyMap::~QDeclarativePropertyMap () [virtual]

Destroys the bindable map.
void QDeclarativePropertyMap::clear ( const QString & key )

Clears the value (if any) associated with key.
bool QDeclarativePropertyMap::contains ( const QString & key ) const

Returns true if the map contains key.

See also size().
int QDeclarativePropertyMap::count () const

This is an overloaded function.

Same as size().
void QDeclarativePropertyMap::insert ( const QString & key, const QVariant & value )

Sets the value associated with key to value.

If the key doesn'
t exist, it is automatically created.
bool QDeclarativePropertyMap::isEmpty () const

Returns true if the map contains no keys; otherwise returns false.

See also size().
int QDeclarativePropertyMap::size () const

Returns the number of keys in the map.

See also isEmpty() and count().
QVariant QDeclarativePropertyMap::value ( const QString & key ) const

Returns the value associated with key.

If no value has been set for this key (or if the value has been cleared), an invalid QVariant is returned.
void QDeclarativePropertyMap::valueChanged ( const QString & key, const QVariant & value ) [signal]

This signal is emitted whenever one of the values in the map is changed. key is the key corresponding to the value that was changed.

Note: valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.
QVariant & QDeclarativePropertyMap::operator[] ( const QString & key )

Returns the value associated with the key key as a modifiable reference.

If the map contains no item with key key, the function inserts an invalid QVariant into the map with key key, and returns a reference to it.

See also insert() and value().
QVariant QDeclarativePropertyMap::operator[] ( const QString & key ) const

This is an overloaded function.

Same as value().


阅读(991) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-10-19 08:42:59

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com