QMap中如何存放三个变量,名词,名词对应的图片,名词的含义解释
时间: 2023-07-15 16:13:15 浏览: 249
Qt中QMap和QMultimap使用
可以使用QMap<QString, QPair<QPixmap, QString>>来实现存放三个变量,其中QPair表示一个名词对应的图片和含义解释,QMap的键值为名词。下面是示例代码:
```cpp
QMap<QString, QPair<QPixmap, QString>> myMap;
myMap.insert("apple", qMakePair(QPixmap("apple.jpg"), "a round fruit with red or green skin"));
myMap.insert("car", qMakePair(QPixmap("car.jpg"), "a vehicle with four wheels, powered by an engine"));
myMap.insert("book", qMakePair(QPixmap("book.jpg"), "a written or printed work consisting of pages glued or sewn together along one side"));
```
这样,可以通过名词来获取对应的图片和含义解释:
```cpp
QString noun = "apple";
QPair<QPixmap, QString> pair = myMap.value(noun);
QPixmap pixmap = pair.first;
QString definition = pair.second;
```
阅读全文