Qt 4.8
Public Functions | Properties | Friends | List of all members
QMetaProperty Class Reference

The QMetaProperty class provides meta-data about a property. More...

#include <qmetaobject.h>

Public Functions

const QMetaObjectenclosingMetaObject () const
 
QMetaEnum enumerator () const
 Returns the enumerator if this property's type is an enumerator type; otherwise the returned value is undefined. More...
 
bool hasNotifySignal () const
 Returns true if this property has a corresponding change notify signal; otherwise returns false. More...
 
bool hasStdCppSet () const
 Returns true if the property has a C++ setter function that follows Qt's standard "name" / "setName" pattern. More...
 
bool isConstant () const
 
bool isDesignable (const QObject *obj=0) const
 Returns true if this property is designable for the given object; otherwise returns false. More...
 
bool isEditable (const QObject *obj=0) const
 Returns true if the property is constant; otherwise returns false. More...
 
bool isEnumType () const
 Returns true if the property's type is an enumeration value; otherwise returns false. More...
 
bool isFinal () const
 
bool isFlagType () const
 Returns true if the property's type is an enumeration value that is used as a flag; otherwise returns false. More...
 
bool isReadable () const
 Returns true if this property is readable; otherwise returns false. More...
 
bool isResettable () const
 Returns true if this property can be reset to a default value; otherwise returns false. More...
 
bool isScriptable (const QObject *obj=0) const
 Returns true if the property is scriptable for the given object; otherwise returns false. More...
 
bool isStored (const QObject *obj=0) const
 Returns true if the property is stored for object; otherwise returns false. More...
 
bool isUser (const QObject *obj=0) const
 Returns true if this property is designated as the USER property, i.e., the one that the user can edit for object or that is significant in some other way. More...
 
bool isValid () const
 Returns true if this property is valid (readable); otherwise returns false. More...
 
bool isWritable () const
 Returns true if this property is writable; otherwise returns false. More...
 
const char * name () const
 Returns this property's name. More...
 
QMetaMethod notifySignal () const
 Returns the QMetaMethod instance of the property change notifying signal if one was specified, otherwise returns an invalid QMetaMethod. More...
 
int notifySignalIndex () const
 Returns the index of the property change notifying signal if one was specified, otherwise returns -1. More...
 
int propertyIndex () const
 Returns this property's index. More...
 
 QMetaProperty ()
 
QVariant read (const QObject *obj) const
 Reads the property's value from the given object. More...
 
bool reset (QObject *obj) const
 Resets the property for the given object with a reset method. More...
 
int revision () const
 Returns the property revision if one was specified by REVISION, otherwise returns 0. More...
 
QVariant::Type type () const
 Returns this property's type. More...
 
const char * typeName () const
 Returns the name of this property's type. More...
 
int userType () const
 Returns this property's user type. More...
 
bool write (QObject *obj, const QVariant &value) const
 Writes value as the property's value to the given object. More...
 

Properties

uint handle
 
int idx
 
QMetaEnum menum
 
const QMetaObjectmobj
 

Friends

struct QMetaObject
 

Detailed Description

The QMetaProperty class provides meta-data about a property.

Property meta-data is obtained from an object's meta-object. See QMetaObject::property() and QMetaObject::propertyCount() for details.

Property Meta-Data

A property has a name() and a type(), as well as various attributes that specify its behavior: isReadable(), isWritable(), isDesignable(), isScriptable(), and isStored().

If the property is an enumeration, isEnumType() returns true; if the property is an enumeration that is also a flag (i.e. its values can be combined using the OR operator), isEnumType() and isFlagType() both return true. The enumerator for these types is available from enumerator().

The property's values are set and retrieved with read(), write(), and reset(); they can also be changed through QObject's set and get functions. See QObject::setProperty() and QObject::property() for details.

Copying and Assignment

QMetaProperty objects can be copied by value. However, each copy will refer to the same underlying property meta-data.

See also
QMetaObject, QMetaEnum, QMetaMethod, {Qt's Property System}

Definition at line 176 of file qmetaobject.h.

Constructors and Destructors

◆ QMetaProperty()

QMetaProperty::QMetaProperty ( )
Warning
This function is not part of the public interface.

Definition at line 2134 of file qmetaobject.cpp.

2135  : mobj(0), handle(0), idx(0)
2136 {
2137 }
const QMetaObject * mobj
Definition: qmetaobject.h:217

Functions

◆ enclosingMetaObject()

const QMetaObject * QMetaProperty::enclosingMetaObject ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 214 of file qmetaobject.h.

214 { return mobj; }
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ enumerator()

QMetaEnum QMetaProperty::enumerator ( ) const

Returns the enumerator if this property's type is an enumerator type; otherwise the returned value is undefined.

See also
isEnumType(), isFlagType()

Definition at line 2294 of file qmetaobject.cpp.

Referenced by QDeclarativeCompiler::genLiteralAssignment(), QDeclarativeCompiler::testLiteralAssignment(), QDeclarativeCompiler::testQualifiedEnumAssignment(), and QDeclarativePropertyPrivate::writeEnumProperty().

2295 {
2296  return menum;
2297 }
QMetaEnum menum
Definition: qmetaobject.h:220

◆ hasNotifySignal()

bool QMetaProperty::hasNotifySignal ( ) const

Returns true if this property has a corresponding change notify signal; otherwise returns false.

See also
notifySignal()

Definition at line 2481 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativeVMEMetaObject::connectAlias(), QDeclarativeProperty::connectNotifySignal(), ShaderEffectItem::connectPropertySignals(), QDeclarativeBindingCompilerPrivate::fetch(), QDeclarativePropertyPrivate::findSignalByName(), QDeclarativeProperty::hasNotifySignal(), notifySignalIndex(), QDeclarativeEngineDebugService::propertyData(), and QDeclarativeWatchProxy::QDeclarativeWatchProxy().

2482 {
2483  if (!mobj)
2484  return false;
2485  int flags = mobj->d.data[handle + 2];
2486  return flags & Notify;
2487 }
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ hasStdCppSet()

bool QMetaProperty::hasStdCppSet ( ) const

Returns true if the property has a C++ setter function that follows Qt's standard "name" / "setName" pattern.

Warning
This function is not part of the public interface.

Designer and uic query hasStdCppSet() in order to avoid expensive QObject::setProperty() calls. All properties in Qt [should] follow this pattern.

Definition at line 2279 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty().

2280 {
2281  if (!mobj)
2282  return false;
2283  int handle = priv(mobj->d.data)->propertyData + 3*idx;
2284  int flags = mobj->d.data[handle + 2];
2285  return (flags & StdCppSet);
2286 }
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isConstant()

bool QMetaProperty::isConstant ( ) const

◆ isDesignable()

bool QMetaProperty::isDesignable ( const QObject object = 0) const

Returns true if this property is designable for the given object; otherwise returns false.

If no object is given, the function returns false if the )'s ;.

See also
isScriptable(), isStored()

Definition at line 2587 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativeProperty::isDesignable(), and QStyleSheetStyle::setProperties().

2588 {
2589  if (!mobj)
2590  return false;
2591  int flags = mobj->d.data[handle + 2];
2592  bool b = flags & Designable;
2593  if (object) {
2594  void *argv[] = { &b };
2595  QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyDesignable,
2596  idx + mobj->propertyOffset(), argv);
2597  }
2598  return b;
2599 
2600 
2601 }
static int metacall(QObject *, Call, int, void **)
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isEditable()

bool QMetaProperty::isEditable ( const QObject object = 0) const

Returns true if the property is constant; otherwise returns false.

Since
4.6
A property is constant if the <tt>)</tt>'s \c; const

{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; return flags & Constant; }

/*!

Returns true if the property is final; otherwise returns false.

\since 4.6


A property is final if the <tt>)</tt>'s \c; const

{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; return flags & Final; }

/*!

Returns true if the property is editable for the given \a object;
otherwise returns false.
If no \a object is given, the function returns false if the
<tt>)</tt>'s \c;.

\sa isDesignable(), isScriptable(), isStored()

Definition at line 2717 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty().

2718 {
2719  if (!mobj)
2720  return false;
2721  int flags = mobj->d.data[handle + 2];
2722  bool b = flags & Editable;
2723  if (object) {
2724  void *argv[] = { &b };
2725  QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyEditable,
2726  idx + mobj->propertyOffset(), argv);
2727  }
2728  return b;
2729 }
static int metacall(QObject *, Call, int, void **)
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isEnumType()

bool QMetaProperty::isEnumType ( ) const

Returns true if the property's type is an enumeration value; otherwise returns false.

See also
enumerator(), isFlagType()

Definition at line 2258 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativeCompiler::compileAlias(), QScript::QtPropertyFunction::execute(), QDeclarativePropertyCache::Data::flagsForProperty(), QDeclarativeCompiler::genLiteralAssignment(), QAxBase::internalProperty(), isFlagType(), qax_generateDocumentation(), read(), QDeclarativeValueTypeScriptClass::setProperty(), QDeclarativeCompiler::testLiteralAssignment(), QDeclarativeCompiler::testQualifiedEnumAssignment(), type(), userType(), write(), and QDeclarativePropertyPrivate::writeEnumProperty().

2259 {
2260  if (!mobj)
2261  return false;
2262  int handle = priv(mobj->d.data)->propertyData + 3*idx;
2263  int flags = mobj->d.data[handle + 2];
2264  return (flags & EnumOrFlag) && menum.name();
2265 }
const char * name() const
Returns the name of the enumerator (without the scope).
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
QMetaEnum menum
Definition: qmetaobject.h:220
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isFinal()

bool QMetaProperty::isFinal ( ) const

◆ isFlagType()

bool QMetaProperty::isFlagType ( ) const

Returns true if the property's type is an enumeration value that is used as a flag; otherwise returns false.

Flags can be combined using the OR operator. A flag type is implicitly also an enum type.

See also
isEnumType(), enumerator(), QMetaEnum::isFlag()

Definition at line 2247 of file qmetaobject.cpp.

Referenced by QDeclarativeCompiler::genLiteralAssignment(), QDeclarativeCompiler::testLiteralAssignment(), QDeclarativeCompiler::testQualifiedEnumAssignment(), write(), and QDeclarativePropertyPrivate::writeEnumProperty().

2248 {
2249  return isEnumType() && menum.isFlag();
2250 }
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
bool isFlag() const
Returns true if this enumerator is used as a flag; otherwise returns false.
QMetaEnum menum
Definition: qmetaobject.h:220

◆ isReadable()

bool QMetaProperty::isReadable ( ) const

Returns true if this property is readable; otherwise returns false.

See also
isWritable(), read(), isValid()

Definition at line 2467 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), generateInterfaceXml(), QAxServerBase::Invoke(), QObject::property(), qax_generateDocumentation(), and readAllProperties().

2468 {
2469  if (!mobj)
2470  return false;
2471  int flags = mobj->d.data[handle + 2];
2472  return flags & Readable;
2473 }
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isResettable()

bool QMetaProperty::isResettable ( ) const

Returns true if this property can be reset to a default value; otherwise returns false.

See also
reset()

Definition at line 2454 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativePropertyCache::Data::flagsForProperty(), and reset().

2455 {
2456  if (!mobj)
2457  return false;
2458  int flags = mobj->d.data[handle + 2];
2459  return flags & Resettable;
2460 }
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isScriptable()

bool QMetaProperty::isScriptable ( const QObject object = 0) const

Returns true if the property is scriptable for the given object; otherwise returns false.

If no object is given, the function returns false if the )'s ;.

See also
isDesignable(), isStored()

Definition at line 2612 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativePropertyCache::append(), QDeclarativeEngineDebugService::buildObjectDump(), QDeclarativeCompiler::buildProperty(), QDeclarativeCompiler::buildValueTypeProperty(), QDeclarativeCompiler::compileAlias(), QDeclarativePropertyCache::create(), QScript::QObjectDelegate::deleteProperty(), QDeclarativeCompiler::doesPropertyExist(), QScript::QtPropertyFunction::execute(), generateInterfaceXml(), QScript::QObjectDelegate::getOwnPropertyDescriptor(), QScript::QObjectDelegate::getOwnPropertySlot(), QScript::isEnumerableMetaProperty(), QScript::QObjectDelegate::put(), qDBusPropertyGet(), readAllProperties(), and writeProperty().

2613 {
2614  if (!mobj)
2615  return false;
2616  int flags = mobj->d.data[handle + 2];
2617  bool b = flags & Scriptable;
2618  if (object) {
2619  void *argv[] = { &b };
2620  QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyScriptable,
2621  idx + mobj->propertyOffset(), argv);
2622  }
2623  return b;
2624 }
static int metacall(QObject *, Call, int, void **)
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isStored()

bool QMetaProperty::isStored ( const QObject object = 0) const

Returns true if the property is stored for object; otherwise returns false.

If no object is given, the function returns false if the )'s ;.

See also
isDesignable(), isScriptable()

Definition at line 2635 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty().

2636 {
2637  if (!mobj)
2638  return false;
2639  int flags = mobj->d.data[handle + 2];
2640  bool b = flags & Stored;
2641  if (object) {
2642  void *argv[] = { &b };
2643  QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyStored,
2644  idx + mobj->propertyOffset(), argv);
2645  }
2646  return b;
2647 }
static int metacall(QObject *, Call, int, void **)
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isUser()

bool QMetaProperty::isUser ( const QObject object = 0) const

Returns true if this property is designated as the USER property, i.e., the one that the user can edit for object or that is significant in some other way.

Otherwise it returns false. e.g., the text property is the USER editable property of a QLineEdit.

If object is null, the function returns false if the {)}'s ;, isDesignable(), isScriptable()

Definition at line 2659 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), and QMetaObject::userProperty().

2660 {
2661  if (!mobj)
2662  return false;
2663  int flags = mobj->d.data[handle + 2];
2664  bool b = flags & User;
2665  if (object) {
2666  void *argv[] = { &b };
2667  QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyUser,
2668  idx + mobj->propertyOffset(), argv);
2669  }
2670  return b;
2671 }
static int metacall(QObject *, Call, int, void **)
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ isValid()

bool QMetaProperty::isValid ( ) const
inline

Returns true if this property is valid (readable); otherwise returns false.

See also
isReadable()

Definition at line 213 of file qmetaobject.h.

Referenced by QScript::QtPropertyFunction::execute(), QScript::QObjectDelegate::getOwnPropertyDescriptor(), QScript::QObjectDelegate::getOwnPropertySlot(), QAxBase::internalProperty(), and QScript::isEnumerableMetaProperty().

213 { return isReadable(); }
bool isReadable() const
Returns true if this property is readable; otherwise returns false.

◆ isWritable()

bool QMetaProperty::isWritable ( ) const

◆ name()

const char * QMetaProperty::name ( ) const

Returns this property's name.

See also
type(), typeName()

Definition at line 2145 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativePropertyCache::append(), QDeclarativeCompiler::buildObject(), QDeclarativeCompiler::buildProperty(), QDeclarativeCompiler::doesPropertyExist(), QDeclarativeVisualDataModelPrivate::ensureRoles(), generateInterfaceXml(), QScript::QObjectDelegate::getOwnPropertyNames(), QAxBase::internalProperty(), QAxServerBase::Invoke(), QScript::isEnumerableMetaProperty(), QAxServerBase::Load(), QDataWidgetMapper::mappedPropertyName(), QDeclarativeProperty::name(), QDeclarativePropertyCache::Data::name(), QDBusAbstractInterfacePrivate::property(), QDeclarativeEngineDebugService::propertyChanged(), QDeclarativeEngineDebugService::propertyData(), QDeclarativeObjectScriptClass::propertyNames(), qax_generateDocumentation(), qax_noSuchFunction(), read(), readAllProperties(), QDeclarativeCompiledBindingsPrivate::run(), QAxServerBase::Save(), QStyledItemDelegate::setEditorData(), QItemDelegate::setEditorData(), QStyledItemDelegate::setModelData(), QItemDelegate::setModelData(), QDeclarativeCompiler::testLiteralAssignment(), QDeclarativeCompiler::testQualifiedEnumAssignment(), and QDeclarativeQtScriptExpression::updateGuards().

2146 {
2147  if (!mobj)
2148  return 0;
2149  int handle = priv(mobj->d.data)->propertyData + 3*idx;
2150  return mobj->d.stringdata + mobj->d.data[handle];
2151 }
const char * stringdata
Definition: qobjectdefs.h:470
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ notifySignal()

QMetaMethod QMetaProperty::notifySignal ( ) const

Returns the QMetaMethod instance of the property change notifying signal if one was specified, otherwise returns an invalid QMetaMethod.

Since
4.5
See also
hasNotifySignal()

Definition at line 2500 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), QDeclarativeProperty::connectNotifySignal(), ShaderEffectItem::connectPropertySignals(), and QDeclarativePropertyPrivate::findSignalByName().

2501 {
2502  int id = notifySignalIndex();
2503  if (id != -1)
2504  return mobj->method(id);
2505  else
2506  return QMetaMethod();
2507 }
int notifySignalIndex() const
Returns the index of the property change notifying signal if one was specified, otherwise returns -1...
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ notifySignalIndex()

int QMetaProperty::notifySignalIndex ( ) const

Returns the index of the property change notifying signal if one was specified, otherwise returns -1.

Since
4.6
See also
hasNotifySignal()

Definition at line 2520 of file qmetaobject.cpp.

Referenced by QDeclarativeVMEMetaObject::connectAlias(), QDeclarativeProperty::connectNotifySignal(), QDeclarativeBindingCompilerPrivate::fetch(), QDeclarativePropertyCache::Data::load(), notifySignal(), and QDeclarativeWatchProxy::QDeclarativeWatchProxy().

2521 {
2522  if (hasNotifySignal()) {
2523  int offset = priv(mobj->d.data)->propertyData +
2524  priv(mobj->d.data)->propertyCount * 3 + idx;
2525  return mobj->d.data[offset] + mobj->methodOffset();
2526  } else {
2527  return -1;
2528  }
2529 }
int methodOffset() const
Returns the method offset for this class; i.e.
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
bool hasNotifySignal() const
Returns true if this property has a corresponding change notify signal; otherwise returns false...
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ propertyIndex()

int QMetaProperty::propertyIndex ( ) const

Returns this property's index.

Since
4.6

Definition at line 2230 of file qmetaobject.cpp.

Referenced by QDeclarativeCompiler::buildProperty(), QDeclarativeCompiler::genLiteralAssignment(), and QDeclarativePropertyCache::Data::load().

2231 {
2232  if (!mobj)
2233  return -1;
2234  return idx + mobj->propertyOffset();
2235 }
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ read()

QVariant QMetaProperty::read ( const QObject object) const

Reads the property's value from the given object.

Returns the value if it was able to read it; otherwise returns an invalid variant.

See also
write(), reset(), isReadable()

Definition at line 2305 of file qmetaobject.cpp.

Referenced by QDeclarativeContext::contextProperty(), QScript::QtPropertyFunction::execute(), QDeclarativeCompiledBindingsPrivate::findproperty(), QScript::QObjectDelegate::getOwnPropertyDescriptor(), QScript::QObjectDelegate::getOwnPropertySlot(), QDeclarativeVisualDataModelDataMetaObject::initialValue(), QDeclarativeVMEMetaObject::metaCall(), QDeclarativeWatchProxy::notifyValueChanged(), QDeclarativeValueTypeScriptClass::property(), QDeclarativeObjectScriptClass::property(), QObject::property(), QDeclarativeEngineDebugService::propertyData(), qDBusPropertyGet(), readAllProperties(), and QDeclarativePropertyPrivate::readValueProperty().

2306 {
2307  if (!object || !mobj)
2308  return QVariant();
2309 
2310  uint t = QVariant::Int;
2311  if (isEnumType()) {
2312  /*
2313  try to create a QVariant that can be converted to this enum
2314  type (only works if the enum has already been registered
2315  with QMetaType)
2316  */
2317  int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
2318  if (enumMetaTypeId != 0)
2319  t = enumMetaTypeId;
2320  } else {
2321  int handle = priv(mobj->d.data)->propertyData + 3*idx;
2322  uint flags = mobj->d.data[handle + 2];
2323  const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1];
2324  t = (flags >> 24);
2325  if (t == 0xff) // special value for QVariant
2326  t = QVariant::LastType;
2327  if (t == QVariant::Invalid)
2328  t = QMetaType::type(typeName);
2329  if (t == QVariant::Invalid)
2330  t = QVariant::nameToType(typeName);
2331  if (t == QVariant::Invalid || t == QVariant::UserType) {
2332  if (t == QVariant::Invalid)
2333  qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name());
2334  return QVariant();
2335  }
2336  }
2337 
2338  // the status variable is changed by qt_metacall to indicate what it did
2339  // this feature is currently only used by QtDBus and should not be depended
2340  // upon. Don't change it without looking into QDBusAbstractInterface first
2341  // -1 (unchanged): normal qt_metacall, result stored in argv[0]
2342  // changed: result stored directly in value
2343  int status = -1;
2344  QVariant value;
2345  void *argv[] = { 0, &value, &status };
2346  if (t == QVariant::LastType) {
2347  argv[0] = &value;
2348  } else {
2349  value = QVariant(t, (void*)0);
2350  argv[0] = value.data();
2351  }
2352  QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::ReadProperty,
2353  idx + mobj->propertyOffset(), argv);
2354 
2355  if (status != -1)
2356  return value;
2357  if (t != QVariant::LastType && argv[0] != value.data())
2358  // pointer or reference
2359  return QVariant((QVariant::Type)t, argv[0]);
2360  return value;
2361 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static int metacall(QObject *, Call, int, void **)
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
const char * stringdata
Definition: qobjectdefs.h:470
static QByteArray qualifiedName(const QMetaEnum &e)
void * data()
Definition: qvariant.cpp:3077
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
const uint * data
Definition: qobjectdefs.h:471
const char * name() const
Returns this property&#39;s name.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
QMetaEnum menum
Definition: qmetaobject.h:220
int propertyOffset() const
Returns the property offset for this class; i.e.
static Type nameToType(const char *name)
Converts the string representation of the storage type given in name, to its enum representation...
Definition: qvariant.cpp:2026
const char * typeName() const
Returns the name of this property&#39;s type.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ reset()

bool QMetaProperty::reset ( QObject object) const

Resets the property for the given object with a reset method.

Returns true if the reset worked; otherwise returns false.

Reset methods are optional; only a few properties support them.

See also
read(), write()

Definition at line 2439 of file qmetaobject.cpp.

2440 {
2441  if (!object || !mobj || !isResettable())
2442  return false;
2443  void *argv[] = { 0 };
2445  return true;
2446 }
static int metacall(QObject *, Call, int, void **)
bool isResettable() const
Returns true if this property can be reset to a default value; otherwise returns false.
int propertyOffset() const
Returns the property offset for this class; i.e.
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ revision()

int QMetaProperty::revision ( ) const

Returns the property revision if one was specified by REVISION, otherwise returns 0.

Warning
This function is not part of the public interface.

Definition at line 2540 of file qmetaobject.cpp.

Referenced by QDeclarativeBindingCompilerPrivate::fetch(), QDeclarativeTypePrivate::init(), and QDeclarativePropertyCache::Data::load().

2541 {
2542  if (!mobj)
2543  return 0;
2544  int flags = mobj->d.data[handle + 2];
2545  if (flags & Revisioned) {
2546  int offset = priv(mobj->d.data)->propertyData +
2547  priv(mobj->d.data)->propertyCount * 3 + idx;
2548  // Revision data is placed after NOTIFY data, if present.
2549  // Iterate through properties to discover whether we have NOTIFY signals.
2550  for (int i = 0; i < priv(mobj->d.data)->propertyCount; ++i) {
2551  int handle = priv(mobj->d.data)->propertyData + 3*i;
2552  if (mobj->d.data[handle + 2] & Notify) {
2553  offset += priv(mobj->d.data)->propertyCount;
2554  break;
2555  }
2556  }
2557  return mobj->d.data[offset];
2558  } else {
2559  return 0;
2560  }
2561 }
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:217

◆ type()

QVariant::Type QMetaProperty::type ( ) const

Returns this property's type.

The return value is one of the values of the QVariant::Type enumeration.

See also
userType(), typeName(), name()

Definition at line 2172 of file qmetaobject.cpp.

Referenced by QDeclarativeCompiler::compileAlias(), QAxBase::internalProperty(), QAxEventSink::OnChanged(), QDBusAbstractInterfacePrivate::property(), QDeclarativeCompiler::testLiteralAssignment(), userType(), and writeProperty().

2173 {
2174  if (!mobj)
2175  return QVariant::Invalid;
2176  int handle = priv(mobj->d.data)->propertyData + 3*idx;
2177  uint flags = mobj->d.data[handle + 2];
2178 
2179  uint type = flags >> 24;
2180  if (type == 0xff) // special value for QVariant
2181  type = QVariant::LastType;
2182  if (type)
2183  return QVariant::Type(type);
2184  if (isEnumType()) {
2185  int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
2186  if (enumMetaTypeId == 0)
2187  return QVariant::Int;
2188  }
2189 #ifdef QT_COORD_TYPE
2190  // qreal metatype must be resolved at runtime.
2191  if (strcmp(typeName(), "qreal") == 0)
2192  return QVariant::Type(qMetaTypeId<qreal>());
2193 #endif
2194 
2195  return QVariant::UserType;
2196 }
static QByteArray qualifiedName(const QMetaEnum &e)
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
QMetaEnum menum
Definition: qmetaobject.h:220
const char * typeName() const
Returns the name of this property&#39;s type.
const QMetaObject * mobj
Definition: qmetaobject.h:217
QVariant::Type type() const
Returns this property&#39;s type.

◆ typeName()

const char * QMetaProperty::typeName ( ) const

◆ userType()

int QMetaProperty::userType ( ) const

Returns this property's user type.

Since
4.2

The return value is one of the values that are registered with QMetaType, or 0 if the type is not registered.

See also
type(), QMetaType, typeName()

Definition at line 2210 of file qmetaobject.cpp.

Referenced by QDeclarativeCompiler::buildProperty(), QDeclarativeCompiler::buildValueTypeProperty(), QScript::QtPropertyFunction::execute(), QDeclarativeBindingCompilerPrivate::fetch(), QDeclarativePropertyCache::Data::flagsForProperty(), QDeclarativeCompiler::genLiteralAssignment(), QDeclarativePropertyPrivate::initProperty(), QDeclarativePropertyCache::Data::load(), QDeclarativeVMEMetaObject::metaCall(), QDeclarativeWatchProxy::notifyValueChanged(), QDeclarativeEngineDebugService::propertyData(), QDeclarativePropertyPrivate::saveValueType(), QDeclarativeValueTypeScriptClass::setProperty(), and QDeclarativeCompiler::testLiteralAssignment().

2211 {
2212  QVariant::Type tp = type();
2213  if (tp != QVariant::UserType)
2214  return tp;
2215  if (isEnumType()) {
2216  int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
2217  return enumMetaTypeId;
2218  }
2219  return QMetaType::type(typeName());
2220 }
static QByteArray qualifiedName(const QMetaEnum &e)
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
QMetaEnum menum
Definition: qmetaobject.h:220
const char * typeName() const
Returns the name of this property&#39;s type.
QVariant::Type type() const
Returns this property&#39;s type.

◆ write()

bool QMetaProperty::write ( QObject object,
const QVariant value 
) const

Writes value as the property's value to the given object.

Returns true if the write succeeded; otherwise returns false.

See also
read(), reset(), isWritable()

Definition at line 2369 of file qmetaobject.cpp.

Referenced by QScript::QtPropertyFunction::execute(), QDeclarativeValueTypeScriptClass::setProperty(), QObject::setProperty(), and writeProperty().

2370 {
2371  if (!object || !isWritable())
2372  return false;
2373 
2374  QVariant v = value;
2375  uint t = QVariant::Invalid;
2376  if (isEnumType()) {
2377  if (v.type() == QVariant::String
2378 #ifdef QT3_SUPPORT
2379  || v.type() == QVariant::CString
2380 #endif
2381  ) {
2382  if (isFlagType())
2383  v = QVariant(menum.keysToValue(value.toByteArray()));
2384  else
2385  v = QVariant(menum.keyToValue(value.toByteArray()));
2386  } else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) {
2387  int enumMetaTypeId = QMetaType::type(qualifiedName(menum));
2388  if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData())
2389  return false;
2390  v = QVariant(*reinterpret_cast<const int *>(v.constData()));
2391  }
2393  } else {
2394  int handle = priv(mobj->d.data)->propertyData + 3*idx;
2395  uint flags = mobj->d.data[handle + 2];
2396  t = flags >> 24;
2397  if (t == 0xff) // special value for QVariant
2398  t = QVariant::LastType;
2399  if (t == QVariant::Invalid) {
2400  const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1];
2401  const char *vtypeName = value.typeName();
2402  if (vtypeName && strcmp(typeName, vtypeName) == 0)
2403  t = value.userType();
2404  else
2405  t = QVariant::nameToType(typeName);
2406  }
2407  if (t == QVariant::Invalid)
2408  return false;
2409  if (t != QVariant::LastType && t != (uint)value.userType() && (t < QMetaType::User && !v.convert((QVariant::Type)t)))
2410  return false;
2411  }
2412 
2413  // the status variable is changed by qt_metacall to indicate what it did
2414  // this feature is currently only used by QtDBus and should not be depended
2415  // upon. Don't change it without looking into QDBusAbstractInterface first
2416  // -1 (unchanged): normal qt_metacall, result stored in argv[0]
2417  // changed: result stored directly in value, return the value of status
2418  int status = -1;
2419  // the flags variable is used by the declarative module to implement
2420  // interception of property writes.
2421  int flags = 0;
2422  void *argv[] = { 0, &v, &status, &flags };
2423  if (t == QVariant::LastType)
2424  argv[0] = &v;
2425  else
2426  argv[0] = v.data();
2428  return status;
2429 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
int keysToValue(const char *keys) const
Returns the value derived from combining together the values of the keys using the OR operator...
static int metacall(QObject *, Call, int, void **)
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
const char * stringdata
Definition: qobjectdefs.h:470
static QByteArray qualifiedName(const QMetaEnum &e)
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
void * data()
Definition: qvariant.cpp:3077
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
bool isFlagType() const
Returns true if the property&#39;s type is an enumeration value that is used as a flag; otherwise returns...
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
const uint * data
Definition: qobjectdefs.h:471
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
const void * constData() const
Definition: qvariant.cpp:3065
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
int keyToValue(const char *key) const
Returns the integer value of the given enumeration key, or -1 if key is not defined.
QMetaEnum menum
Definition: qmetaobject.h:220
int propertyOffset() const
Returns the property offset for this class; i.e.
static Type nameToType(const char *name)
Converts the string representation of the storage type given in name, to its enum representation...
Definition: qvariant.cpp:2026
const char * typeName() const
Returns the name of this property&#39;s type.
const QMetaObject * mobj
Definition: qmetaobject.h:217

Friends and Related Functions

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 221 of file qmetaobject.h.

Properties

◆ handle

uint QMetaProperty::handle
private

◆ idx

int QMetaProperty::idx
private

◆ menum

QMetaEnum QMetaProperty::menum
private

◆ mobj

const QMetaObject* QMetaProperty::mobj
private

The documentation for this class was generated from the following files: