I’m trying to work with flags returned by a web service that was developed in .NET C#. The flags are returned in a json object as a string separated by commas ex: roomA,roomB,auditorium. My Qt c++ app is using an enum with a bit set for each of the flags:
enum AccessMask
{
None = 0,
roomA = 1 << 1,
roomB = 1 << 2,
ownerOnly = 1 << 3,
workgroup = 1 << 4,
department = 1 << 5,
auditorium = 1 << 6
}
Is there a better way to set an access mask other than doing many ‘if QString.contains()’ statements?
You could use a dictionary or map that have a string as key and the enum-value as data. Then you could split the string at the comma and do an easy look-up of the values.