Qt 4.8
|
The QMetaType class manages named types in the meta-object system. More...
#include <qmetatype.h>
Public Types | |
typedef void *(* | Constructor) (const void *) |
typedef void(* | Destructor) (void *) |
typedef void(* | LoadOperator) (QDataStream &, void *) |
typedef void(* | SaveOperator) (QDataStream &, const void *) |
enum | Type { Void = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5, Double = 6, QChar = 7, QVariantMap = 8, QVariantList = 9, QString = 10, QStringList = 11, QByteArray = 12, QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17, QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22, QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27, QVariantHash = 28, QEasingCurve = 29, LastCoreType = QEasingCurve, FirstGuiType = 63, QFont = 64, QPixmap = 65, QBrush = 66, QColor = 67, QPalette = 68, QIcon = 69, QImage = 70, QPolygon = 71, QRegion = 72, QBitmap = 73, QCursor = 74, QSizePolicy = 75, QKeySequence = 76, QPen = 77, QTextLength = 78, QTextFormat = 79, QMatrix = 80, QTransform = 81, QMatrix4x4 = 82, QVector2D = 83, QVector3D = 84, QVector4D = 85, QQuaternion = 86, LastGuiType = QQuaternion, FirstCoreExtType = 128, VoidStar = 128, Long = 129, Short = 130, Char = 131, ULong = 132, UShort = 133, UChar = 134, Float = 135, QObjectStar = 136, QWidgetStar = 137, QVariant = 138, LastCoreExtType = QVariant, QReal = Double, User = 256 } |
These are the built-in types supported by QMetaType: More... | |
Static Public Functions | |
static void * | construct (int type, const void *copy=0) |
Returns a copy of copy, assuming it is of type type. More... | |
static void | destroy (int type, void *data) |
Destroys the data, assuming it is of the type given. More... | |
static bool | isRegistered (int type) |
Returns true if the datatype with ID type is registered; otherwise returns false. More... | |
static bool | load (QDataStream &stream, int type, void *data) |
Reads the object of the specified type from the given stream into data. More... | |
static void | registerStreamOperators (const char *typeName, SaveOperator saveOp, LoadOperator loadOp) |
static void | registerStreamOperators (int type, SaveOperator saveOp, LoadOperator loadOp) |
static int | registerType (const char *typeName, Destructor destructor, Constructor constructor) |
Registers a user type for marshalling, with typeName, a destructor, and a constructor. More... | |
static int | registerTypedef (const char *typeName, int aliasId) |
static bool | save (QDataStream &stream, int type, const void *data) |
Writes the object pointed to by data with the ID type to the given stream. More... | |
static int | type (const char *typeName) |
Returns a handle to the type called typeName, or 0 if there is no such type. More... | |
static const char * | typeName (int type) |
Returns the type name associated with the given type, or 0 if no matching type was found. More... | |
static void | unregisterType (const char *typeName) |
Unregisters a user type, with typeName. More... | |
Related Functions | |
(Note that these are not member functions.) | |
int | qMetaTypeId () |
Returns the meta type id of type T at compile time. More... | |
int | qRegisterMetaType (const char *typeName) |
int | qRegisterMetaType () |
Call this function to register the type T . More... | |
int | qRegisterMetaTypeStreamOperators (const char *typeName) |
The QMetaType class manages named types in the meta-object system.
The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. It associates a type name to a type so that it can be created and destructed dynamically at run-time. Declare new types with Q_DECLARE_METATYPE() to make them available to QVariant and other template-based functions. Call qRegisterMetaType() to make type available to non-template based functions, such as the queued signal and slot connections.
Any class or struct that has a public default constructor, a public copy constructor, and a public destructor can be registered.
The following code allocates and destructs an instance of MyClass
:
If we want the stream operators operator<<()
and operator>>()
to work on QVariant objects that store custom types, the custom type must provide operator<<()
and operator>>()
operators.
Definition at line 62 of file qmetatype.h.
QMetaType::Constructor |
Definition at line 105 of file qmetatype.h.
QMetaType::Destructor |
Definition at line 104 of file qmetatype.h.
QMetaType::LoadOperator |
Definition at line 109 of file qmetatype.h.
QMetaType::SaveOperator |
Definition at line 108 of file qmetatype.h.
enum QMetaType::Type |
These are the built-in types supported by QMetaType:
void
bool
int
unsigned int
double
void *
long
short
char
unsigned long
unsigned short
unsigned char
float
Additional types can be registered using Q_DECLARE_METATYPE().
Definition at line 64 of file qmetatype.h.
|
static |
Returns a copy of copy, assuming it is of type type.
If copy is zero, creates a default type.
Definition at line 1042 of file qmetatype.cpp.
Referenced by QTestData::append(), construct(), QMetaMethod::invoke(), qax_createObjectWrapper(), and queued_activate().
|
static |
Destroys the data, assuming it is of the type given.
Definition at line 1263 of file qmetatype.cpp.
Referenced by clear(), QMetaMethod::invoke(), QMetaCallEvent::~QMetaCallEvent(), and QTestData::~QTestData().
|
static |
Returns true if the datatype with ID type is registered; otherwise returns false.
Definition at line 590 of file qmetatype.cpp.
Referenced by compare().
|
static |
Reads the object of the specified type from the given stream into data.
Returns true if the object is loaded successfully; otherwise returns false.
The type must have been registered with qRegisterMetaType() and qRegisterMetaTypeStreamOperators() beforehand.
Normally, you should not need to call this function directly. Instead, use QVariant's operator>>()
, which relies on load() to stream custom types.
Definition at line 845 of file qmetatype.cpp.
Referenced by QVariant::load().
|
static |
Definition at line 374 of file qmetatype.cpp.
|
static |
Definition at line 385 of file qmetatype.cpp.
|
static |
Registers a user type for marshalling, with typeName, a destructor, and a constructor.
Returns the type's handle, or -1 if the type could not be registered.
Definition at line 477 of file qmetatype.cpp.
Referenced by QDeclarativeEnginePrivate::registerCompositeType().
|
static |
Registers a user type for marshalling, as an alias of another type (typedef)
Definition at line 515 of file qmetatype.cpp.
Referenced by qRegisterMetaType().
|
static |
Writes the object pointed to by data with the ID type to the given stream.
Returns true if the object is saved successfully; otherwise returns false.
The type must have been registered with qRegisterMetaType() and qRegisterMetaTypeStreamOperators() beforehand.
Normally, you should not need to call this function directly. Instead, use QVariant's operator<<()
, which relies on save() to stream custom types.
Definition at line 646 of file qmetatype.cpp.
Referenced by QVariant::save().
|
static |
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition at line 607 of file qmetatype.cpp.
Referenced by MetaObjectGenerator::addProperty(), QAxBase::asVariant(), QDeclarativeObjectMethodScriptClass::callOverloaded(), QDeclarativeObjectMethodScriptClass::callPrecise(), QScript::callQtMethod(), QScriptEnginePrivate::convertValue(), QScript::QObjectConnectionManager::execute(), QDBusMetaObjectGenerator::findType(), QStateMachinePrivate::handleTransitionSignal(), QSignalSpy::initArgs(), QAxBase::internalInvoke(), QMetaMethod::invoke(), QAxServerBase::Invoke(), QScriptEnginePrivate::jscValueToVariant(), QDeclarativePropertyCache::Data::load(), QVariant::load(), QVariant::nameToType(), QScriptEnginePrivate::newQObject(), QDeclarativeDomDynamicProperty::propertyType(), qDBusNameToTypeId(), QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(), QTest::qSignalDumperCallback(), QAxServerBase::qt_metacall(), QAxBase::querySubObject(), queuedConnectionTypes(), qvariant_nameToType(), QVariantToVARIANT(), QMetaProperty::read(), QMetaProperty::type(), QScript::QScriptMetaType::typeId(), QMetaProperty::userType(), QScript::variantFromValue(), VARIANTToQVariant(), QMetaProperty::write(), and QDeclarativePropertyPrivate::writeEnumProperty().
|
static |
Returns the type name associated with the given type, or 0 if no matching type was found.
The returned pointer must not be deleted.
Definition at line 406 of file qmetatype.cpp.
Referenced by QTestData::append(), compare(), convert(), QScriptEnginePrivate::convertValue(), QScriptEnginePrivate::create(), QDBusConnectionPrivate::deliverCall(), QTest::fetchData(), QScript::QScriptMetaType::name(), QVariant::save(), QDBusPendingCallPrivate::setMetaTypes(), QDeclarativeObjectScriptClass::setProperty(), QVariant::typeToName(), and QDeclarativeBinding::update().
|
static |
Unregisters a user type, with typeName.
Definition at line 561 of file qmetatype.cpp.
|
related |
Returns the meta type id of type T
at compile time.
If the type was not declared with Q_DECLARE_METATYPE(), compilation will fail.
Typical usage:
QMetaType::type() returns the same ID as qMetaTypeId(), but does a lookup at runtime based on the name of the type. QMetaType::type() is a bit slower, but compilation succeeds if a type is not registered.
Definition at line 224 of file qmetatype.h.
|
related |
Registers the type name typeName for the type T
. Returns the internal ID used by QMetaType. Any class or struct that has a public default constructor, a public copy constructor and a public destructor can be registered.
After a type has been registered, you can create and destroy objects of that type dynamically at run-time.
This example registers the class MyClass
:
This function is useful to register typedefs so they can be used by QMetaProperty, or in QueuedConnections
Definition at line 185 of file qmetatype.h.
|
related |
Call this function to register the type T
.
T
must be declared with Q_DECLARE_METATYPE(). Returns the meta type Id.
Example:
To use the type T
in QVariant, using Q_DECLARE_METATYPE() is sufficient. To use the type T
in queued signal and slot connections, qRegisterMetaType<T>()
must be called before the first connection is established.
Also, to use type T
with the QObject::property() API, qRegisterMetaType<T>()
must be called before it is used, typically in the constructor of the class that uses T
, or in the main()
function.
Definition at line 234 of file qmetatype.h.
Referenced by convertTypes(), qAxFactory(), qmlRegisterCustomType(), qmlRegisterExtendedType(), qmlRegisterInterface(), qmlRegisterRevision(), qmlRegisterType(), and qmlRegisterUncreatableType().
|
related |
Registers the stream operators for the type T
called typeName.
Afterward, the type can be streamed using QMetaType::load() and QMetaType::save(). These functions are used when streaming a QVariant.
The stream operators should have the following signatures:
Definition at line 206 of file qmetatype.h.