1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <QCoreApplication> #include <QVariant> #include <QString> struct MyStruct { int a; double b; QString c; }; struct MyPowerStruct { int a; double b; MyStruct c; }; Q_DECLARE_METATYPE(MyStruct) Q_DECLARE_METATYPE(MyPowerStruct) int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); MyStruct v01 = { 1, 5.0, QString("Nokia Qt") }; QVariant var0; var0.setValue(v01); MyStruct v02 = var0.value(); MyPowerStruct v11 = { 10, 0.5, {1, 5.0, QString("Nokia Qt") } }; QVariant var1; var1.setValue(v11); MyPowerStruct v12 = var1.value(); return 0; } |
Reference:
Qt 4.6 Documentation: Q_DECLARE_METATYPE