[Interest] Accessing existing enums from QML

Jan Kundrát jkt at flaska.net
Wed May 7 19:31:58 CEST 2014


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;
  }

I also have some classes derived from QObject which accept these enums as 
an argument. This works just fine from C++. I would like to export these 
methods to QML, but I'm having trouble coming up with a scheme which will 
allow my QML code to access these enums.

The documentation [1] says that "C++ signals and methods with 
enumeration-type parameters can be used from QML provided that the 
enumeration and the signal or method are both declared within the same 
class, or that the enumeration value is one of those declared in the Qt 
Namespace.". That's clearly not the case for these existing methods, and 
the idea of changing our C++ code in order to accommodate a random QML 
requirement looks rather weird.

What would be the easiest way of making this work? A typedef? Or some hack 
to register that type through qmlRegisterType?

With kind regards,
Jan

[1] 
http://qt-project.org/doc/qt-5/qtqml-cppintegration-data.html#enumeration-types-as-signal-and-method-parameters

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/



More information about the Interest mailing list