Search code examples
c++qtsortingqmap

Sort QMap<QString, int>


I have data struct QMap<QString, int> how can i sort it by int key?

Thank you.


Solution

  • 1) Create std::map<int, std::string> and push all data to it (or your QString and QMap).

    or

    2) Create std::vector<std::pair<int, std::string>> vec, push all data to it and call std::sort(vec.begin(), vec.end());

    or

    3) Use boost::bimap