[Solved] How to convert size_t to enum from boost in Qt?
-
I have a boost map and it's key variables' datatype is size_t. I'm reading the map from shared memory and I need to copy it to my local QMap.
This is how the boost map looks in our application -
@typedef boost::interprocess::map<size_t, char_string, std::less<size_t>, size_t_string_map_value_type_allocator> size_t_string_map_type;
// -- v: My local Qt map
QMap<Config, QString> my_QtMap;@And here is how I get read the values from boost map into QMap
@size_t_string_map_type* configmapshared = shm.find<size_t_string_map_type>("configmap").first;
size_t_string_map_type::iterator it;
for(it = configmapshared.begin(); it != configmapshared.end; it++)
{
my_QtMap.insert(it->first, QString::fromUtf8(it->second.c_str()));
// it->first need to be converted to my enum "Config"
}@
How do I convert to my enum called Config ? Kindly help me.
Thank you. -
bq. How do I convert [size-t] to my enum called Config ?
With a C++ cast and a good deal of caution given that size_t implies an unbounded unsigned integer and an enum is bounded and not necessarily unsigned or contiguous.
@
size_t from = 45;
Config to = static_cast<Config>(from);
// undefined if from not a valid Config value
@
This is basic C++, nothing to do with Qt or Boost, and readily answered with Google. -
Thanks ChrisW67. I did the same, but forgot about the braces for (from). I corrected it.