简体   繁体   中英

Accessing QMap of QMap<QString, QPair<int, int>>

Is it possible to write and initialize

QMap<QString, QPair<int, int>>

in Qt 5.10 ?

For example I want to do that

QMap<QString, QPair<int, int>> ee{"MAC", 0,0,};  // string, section 0, line 0

When I supply Mac , I need to retrieve the pair 0,0

 eepromDictionary = QMap<QString, QPair<int, int>>{ {
                                                      "MAC", {0,0},
                                                      "IP", {0,0},
                                                      "Mask", {0,0},
                                                      "ID", {0,0},
                                                      "Gateway", {0,0},
                                                      "Date", {0,0}
                                                      }

                                                      };

Note that the QMap(initializer_list<pair<Key, T>> takes pair<Key, T> as it's elements. It should be sufficient to wrap each element in it's own braces. For example:

QMap<QString, QPair<int, int>> ee = {{"MAC", {0, 0}}}

If you were going to initialize a second element of ee you could extend the initializer_list like so: {{"MAC", {0, 0}}, {"DONALDS", {0, 0}}}

通过这种方式初始化: ee{"MAC", {0,0} }您只是初始化一个列表元素,您缺少List的括号,这样做可以解决问题:

QMap<QString, QPair<int, int>> ee{ {"MAC", {0,0} } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM