Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

KDAB contributions to Qt 5.0 (part 1)

Q_DECLARE_METATYPE(MyObject*)
QVariant var = QVariant::fromValue(myObjectInstance);
Q_DECLARE_METATYPE(QList<int>)
 Q_DECLARE_METATYPE(QList<QObject*>)
 // Because MyObject* is automatically a metatype from above!
 Q_DECLARE_METATYPE(QList<MyObject*>)
 Q_DECLARE_METATYPE(QSharedPointer<<MyObject*>>)
 // Because QList<MyObject*> is automatically a metatype from above!
 Q_DECLARE_METATYPE(QVector<QList<MyObject*>>)
struct SomeStruct {};
 Q_DECLARE_METATYPE(SomeStruct)
 // No need for Q_DECLARE_METATYPE(QList<SomeStruct>)

 // later:
 QList<SomeStruct> structs;
 QVariant var = QVariant::fromValue(structs);
MyObject *myObjectInstance = ...;
 QVariant var = QVariant::fromValue(myObjectInstance);

 // elsewhere...
 if (var.canConvert())
 {
   QObject *obj = var.value();
   // Use the properties of obj
 }
QLabel* l = new QLabel;
 l.setObjectName("someLabel");
 QVariant var = QVariant::fromValue(l);
 qDebug() << var;
 // Qt 4 prints: QVariant(QLabel*, )
 // Qt 5 prints: QVariant(QLabel*, QLabel(0x7fff792fefa0, name = "someLabel") ))

14 Comments

20 - Dec - 2012

klaatu

20 - Dec - 2012

Bernhard Friedreich

20 - Dec - 2012

Sandro Andrade

20 - Dec - 2012

Sandro Andrade

21 - Dec - 2012

steveire

21 - Dec - 2012

Sandro

29 - Dec - 2012

Sandro Andrade

29 - Dec - 2012

steveire

30 - Dec - 2012

Sandro Andrade

30 - Dec - 2012

steveire

31 - Dec - 2012

Sandro Andrade

4 - Mar - 2013

Sandro Andrade

namespace QtUml {
    class QClass ...
        Q_PROPERTY(p1 ...)
        ...
        Q_PROPERTY(pn ...)
}
namespace QtMof {
    class QClass ...
        Q_PROPERTY(p1 ...)
        ...
        Q_PROPERTY(pm ...)
}

n > m

4 - Mar - 2013

steveire

4 - Mar - 2013

Sandro Andrade

QT_BEGIN_NAMESPACE_QTMOF
QT_BEGIN_NAMESPACE
namespace QtMof {