Note that there are some explanatory texts on larger screens.

plurals
  1. POExposing Qt's Q_ENUMS to QML
    text
    copied!<p>I might be missing something obvious here, but when trying to expose a Q_ENUM to QML, even in the most simple case, does not seem to work as shown in the QT docs (<a href="http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#using-enumerations-of-a-custom-type" rel="noreferrer">http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#using-enumerations-of-a-custom-type</a>)</p> <p>I've created a simple test case, my C++ class looks like:</p> <pre><code>class MyClass : public QDeclarativeItem { Q_OBJECT Q_ENUMS(testType) public: MyClass() : t(FirstValue) { } enum testType { InvalidValue, FirstValue, SecondValue } ; testType testVal() const { return t; } Q_PROPERTY(testType testVal READ testVal NOTIFY testValChanged) private: testType t; signals: void testValChanged(); }; </code></pre> <p>I then register &amp; inject an instance of this class into the QDeclartiveContext.</p> <p>When I try and access the testVal property, it returns the integer (1 in this case) rather than a string representation. In addition, with the instance injected as 'aVar', if I try and access 'aVar.FirstValue', the result is 'undefined' </p> <p>So this means I can't do tests like: <code>'if aVar.testVal == FirstValue'</code> (ReferenceError for the unqualified FirstValue)</p> <p>Or like this: <code>'if aVar.testVal == aVar.FirstValue'</code> (<code>aVar.FirstValue</code> is undefined)</p> <p>Anyone been through this before? It seems to conflict with example provided in the QT docs, although, the Object is instantiated from QML in that example, so this might be the cause.. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload