_Bits with anxiety disorder

About RSS
Feb 22, 2011 | #KDE #poo #Programming #cpp #kde #plugin #quanta

typedef, union, QVariant and QMetatype.

Just some notes about typedef, union, QVariant e QMetatype:

typedef: allow the definition of our own types based on other existing data types.

typedef existing_type new_type_name;

typedef does not create a new type. It only create synonyms of a existing type.

union: allow one same portion of memory to be acessed as different data types, since all of them are in fact the same location in memory.

union union_name {
member_type1  member_name1;
member_type2 member_name2;
member_type3 member_name3;
member_type4 member_name4;
} object_names;

All the elemenst of the union declaration occupy the same physical space in memory. Its size is the one or the greatest. We can not store different values them independent of each other.

QVariant: the QVariant class acts like a union for the most common Qt Data types.

C++ forbids unions from including types that have non-defaults constructor or destructor.

A QVariant objects holds a single value of a single type at time.

QMetatype: It associates a type name to a type, so that it can be created and destructed dynamically at runtime.

Declare Q_DECLARE_METATYPE(type) to make them avaliable to QVariant.

QString, QByteArray and QVariant are three classes that have many things in common with containers and that can be used as alternatives to containers in some context. Also like the containers, these classes use implicit sharing as memory and speed optmization.

Fonts:
doc.qt.nokia.com
www.cplusplus.com
…........................................................................................................................

With these notes I intend to finish some new features in my plugin for Quanta :)