We personnaly expose another property into those case (in your WebSockets C++ class):
Q_PROPERTY(QVarianMap enumToStringMap READ enum_to_string CONST); QVarianMap WebSockets::enum_to_string() { return QVariantMap { std::make_pair<int, QString>(WebSockets::Connecting, QString("Connecting")) , std::make_pair<int, QString>(WebSockets::Open, QString("Open")) ... }; } This way you can convert to string easily and access it too with the string: property string myValue: myWebSocketsId.enumToStringMap[myIntValue] you can even go the other way property int myInt: WebSockets["Open"] or even: function printAllValue() { for(key in myWebSocketsId.enumToStringMap) { console.log(key.toString() + " : " + myWebSocketsId. enumToStringMap[key]); } } This make it way easier to deal with enum and available value. On Tue, Sep 20, 2016 at 3:34 PM, Jason H <jh...@gmx.com> wrote: > Without having to create my own mapping object, I'd like to get the name > from values: > > WebSocket { > id: webSocket > onStatusChanged: console.log("webSocket status:", status) // > prints 3 or 4 > } > > I'd like to be able to do: > onStatusChanged: console.log("secWebSocket status:", > WebSocket.Status(status)) // prints "Open" or "Closed" > > or something like that... > WebSocket.enum(Status).value(status)), WebSocket.enumValue(Status, > status), WebSocket.Enums.Status.value(4). I don't really care, I just > want to have to explore the mapping myself. I say explore, because the docs > say: > > > status : Status > > Status of the WebSocket. > The status can have the following values: > WebSockets.Connecting > WebSockets.Open > WebSockets.Closing > WebSockets.Closed > WebSockets.Error > > > So then I have to go through and go through a trivial mapping exercise to > find out what the constants are. > > > Is there a better way to do this? > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest