Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to convert size_t to enum from boost in Qt?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to convert size_t to enum from boost in Qt?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rawfool
    wrote on 25 Jun 2013, 14:57 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 25 Jun 2013, 20:46 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rawfool
        wrote on 26 Jun 2013, 04:42 last edited by
        #3

        Thanks ChrisW67. I did the same, but forgot about the braces for (from). I corrected it.

        1 Reply Last reply
        0

        1/3

        25 Jun 2013, 14:57

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved