[Interest] Qt::Alignment and MetaObject System
Martin Koller
kollix at aon.at
Thu Aug 29 17:11:57 CEST 2013
Hi,
I'd like to programmatically get the enum values for Qt::Alignment (Qt::AlignmentFlag) as strings.
I do this in my code already for e.g. SizePolicy like that:
int idx = QSizePolicy::staticMetaObject.indexOfEnumerator("Policy");
QMetaEnum metaEnum = QSizePolicy::staticMetaObject.enumerator(idx);
for (int i = 0; i < metaEnum.keyCount(); i++)
{
hor->appendId(metaEnum.value(i), metaEnum.key(i));
ver->appendId(metaEnum.value(i), metaEnum.key(i));
}
However how can I do the same with this Qt::AlignmentFlag enum which is not defined inside a QObject ?
I even could not get it to work when I have an own QObject derived class, like:
#include <QObject>
#include <QMetaEnum>
#include <iostream>
class Object : public QObject
{
Q_OBJECT
Q_PROPERTY(Qt::Alignment alignment READ getAlignment)
public:
Qt::Alignment getAlignment() const { return Qt::AlignCenter; }
void printEnums()
{
for (int i = 0; i < QObject::staticMetaObject.enumeratorCount(); i++)
std::cerr << QObject::staticMetaObject.enumerator(i).name()
<< " scope:" << QObject::staticMetaObject.enumerator(i).scope() << std::endl;
for (int i = 0; i < metaObject()->enumeratorCount(); i++)
std::cerr << metaObject()->enumerator(i).name()
<< " scope:" << metaObject()->enumerator(i).scope() << std::endl;
}
};
--
Best regards/Schöne Grüße
Martin
A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
Geschenkideen, Accessoires, Seifen, Kulinarisches: www.bibibest.at
More information about the Interest
mailing list