当前位置:网站首页>QT notes qmap user defined key
QT notes qmap user defined key
2022-06-22 16:58:00 【IT1995】
as follows key value :
struct MyKey{
MyKey(QString key1, int key2){
this->key1 = key1;
this->key2 = key2;
}
QString key1;
int key2;
};Customize key The following problems will occur when :

The left operation symbol needs to be rewritten , as follows :
struct MyKey{
MyKey(QString key1, int key2){
this->key1 = key1;
this->key2 = key2;
}
bool operator < (const MyKey &key) const{
return std::tie(key1, key2) < std::tie(key.key1, key.key2);
}
QString key1;
int key2;
};All the source codes are as follows :
#include <QCoreApplication>
#include <QMap>
#include <QDebug>
struct MyKey{
MyKey(QString key1, int key2){
this->key1 = key1;
this->key2 = key2;
}
bool operator < (const MyKey &key) const{
return std::tie(key1, key2) < std::tie(key.key1, key.key2);
}
QString key1;
int key2;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QMap<MyKey, QString> map;
map.insert(MyKey("10086", 0), "value1");
map.insert(MyKey("10086", 1), "value2");
map.insert(MyKey("10086", 2), "value3");
map.insert(MyKey("10010", 1), "value4");
map.insert(MyKey("10010", 2), "value5");
return a.exec();
}
The debugging screenshot is as follows :

Source code package download address :
边栏推荐
- spark常用 算子小总结
- 【微信小程序封装底部弹出框二】
- What is the difference between "img" and "ALT" in the interview question
- Short video source code development, high-quality short video source code need to do what?
- [C language] use of library function qsort
- LETV group payment system architecture sharing for processing 100000 high concurrent orders per second
- 短视频源码开发,优质的短视频源码需要做好哪几点?
- mysql指令执行sql文件
- Spark and mysql:did not find registered driver with class com mysql. jdbc. Driver
- vs2017 在调试状态不显示QString值的解决方法
猜你喜欢

视频爆炸时代,谁在支撑视频生态网高速运行?

网传学习通1.7亿密码泄露!有什么补救措施?

洞见科技牵头的全球「首个」IEEE隐私计算「互联互通」国际标准正式启动

高可用性的ResourceManager
![[deep anatomy of C language] keywords if & else & bool type](/img/cf/a0533b7d3a597368aefe6ce7fd6dbb.png)
[deep anatomy of C language] keywords if & else & bool type

新手必会的静态站点生成器——Gridsome

5 modes of IO model

Linux system maintenance: mysql8.0.13 source code download and installation "fool" operation steps (Linux centos6.8) test available series

【微信小程序获取自定义tabbar的高度】绝对可用!!!

Windows8.1 64 installed by mysql5.7.27
随机推荐
Interview knowledge points
【心理学】情感心理学-当代思想和传统思想的碰撞(本篇文章将不定期持续更新)
How to add a "security lock" to the mobile office of government and enterprises?
Database mysql master-slave scheme
超出文本部分用省略号表示
Analysis of the read data source code of spark shuffle
jsp学习之(二)---------jsp脚本元素和指令
[C language] deeply analyze the relationship between pointer and array
[wechat applet custom bottom tabbar]
spark常用 算子小总结
Short video source code development, high-quality short video source code need to do what?
[C language] use of library function qsort
Test for API
让代码优雅起来(学会调试+代码风格)
mysql-5.6.21-centos6.5源码安装配置
redis.clients.jedis.exceptions.JedisDataException ERR invalid password.
jsp学习之(一)---------jsp概述
Call CMD process communication
scala-for的基本应用
spark-cache的源码分析
https://github.com/fengfanchen/Qt/tree/master/QMapKeyCustom