[Interest] Accessing existing enums from QML
Kristoffersen, Even (NO14)
Even.Kristoffersen at Honeywell.com
Wed May 14 09:04:15 CEST 2014
>Subject: [Interest] Accessing existing enums from QML
>
>Hi,
>my C++ code makes heavy use of quite simple enums which are defined in some namespace, outside of any class >(and therefore also outside of any class which derives from QObject). It's done like this:
>
> namespace Imap {
> typedef enum { FLAG_ADD, FLAG_REMOVE } FlagsOperation;
> }
You can add a wrapper class for the enum inside the namespace for your Qt C++/QML code, non-Qt C++ won't change:
namespace Imap
{
#ifdef QT_VERSION
#include <QObject>
class ImplementDirectExpositionOfEnumsToQmlPrettyPlease : public QObject
{
Q_OBJECT
Q_ENUMS(FlagsOperation)
public:
explicit ImplementDirectExpositionOfEnumsToQmlPrettyPlease(QObject* parent = 0) : QObject(parent) { }
#endif
typedef enum { FLAG_ADD, FLAG_REMOVE } FlagsOperation;
#ifdef QT_VERSION
}
#endif
}
(choose a handy class name that is short, but easy to search & replace when the work-around is no longer needed)
It's not the prettiest solution, but it will get you by until there is support for non-qobject enums exposed to QML.
-Even
More information about the Interest
mailing list