Hi,
I'm in need of using the reflection power of QT, so I recently implemented Qt5.6.1 on my project, I would like to be able to retrieve any data inside my object using string, but i can't get the Q_Declare_MetaType() to work, but i can still get metadata inside my class
eg :
//This Work
auto metaEnum
= QMetaEnum::fromType<FRShapeNode
::FRSHAPE_TYPE>
();
EASYPRINT("%s yo", metaEnum.valueToKey(FRShapeNode::FRSHAPE_TYPE::CV_CIRCLE))
//This Dont (QMetaType::type("FRSHapeNode") return 0)
int classId
= QMetaType::type("FRShapeNode");
auto metaObject
= QMetaType::metaObjectForType(classId
);
int enumId = metaObject->indexOfEnumerator("FRSHAPE_TYPE");
QMetaEnum e
= metaObject
->enumerator
(enumId
);
for (int i = 0; i < e.keyCount(); i++)
{
const char* s = e.key(i); // enum name as string
int v = e.value(i); // enum index
appendToResult(MString(s) + "=" + v);
}
}
//This Work
auto metaEnum = QMetaEnum::fromType<FRShapeNode::FRSHAPE_TYPE>();
EASYPRINT("%s yo", metaEnum.valueToKey(FRShapeNode::FRSHAPE_TYPE::CV_CIRCLE))
//This Dont (QMetaType::type("FRSHapeNode") return 0)
int classId = QMetaType::type("FRShapeNode");
if (classId != QMetaType::UnknownType) {
auto metaObject = QMetaType::metaObjectForType(classId);
int enumId = metaObject->indexOfEnumerator("FRSHAPE_TYPE");
QMetaEnum e = metaObject->enumerator(enumId);
for (int i = 0; i < e.keyCount(); i++)
{
const char* s = e.key(i); // enum name as string
int v = e.value(i); // enum index
appendToResult(MString(s) + "=" + v);
}
}
To copy to clipboard, switch view to plain text mode
here is my .hpp of the class i'm trying to register :
#pragma once
#include "FRDagNode.h"
#include <QObject>
class FRShapeNode : public FRDagNode
{
Q_GADGET
public:
FRShapeNode();
FRShapeNode(const FRShapeNode &other) { }
~FRShapeNode();
static MTypeId id;
enum FRSHAPE_TYPE
{
CV_CIRCLE = 0,
CV_LINE,
CV_CUSTOM
};
Q_ENUM(FRSHAPE_TYPE)
protected:
typedef FRDagNode super;
};
Q_DECLARE_METATYPE(FRShapeNode)
#pragma once
#include "FRDagNode.h"
#include <QObject>
class FRShapeNode : public FRDagNode
{
Q_GADGET
public:
FRShapeNode();
FRShapeNode(const FRShapeNode &other) { }
~FRShapeNode();
static MTypeId id;
enum FRSHAPE_TYPE
{
CV_CIRCLE = 0,
CV_LINE,
CV_CUSTOM
};
Q_ENUM(FRSHAPE_TYPE)
protected:
typedef FRDagNode super;
};
Q_DECLARE_METATYPE(FRShapeNode)
To copy to clipboard, switch view to plain text mode
I'm pretty new with Qt c++, I was mostly using Pyside for month.
I'm Using Qt5.6.1 and compiling my project as a dynamic Library, which is then loaded inside Maya 2017.
Bookmarks