hair_man 2015-08-17 08:09 采纳率: 51.6%
浏览 3091
已采纳

QMultiHash建立QMultiHash<key,t>时遇到问题

请问建立一个 一对多的映射,使用了QMultiHash,全局的qHash怎么写?
重载了==运算符后,报错,主要不会qHash,也不明白。
补充:我所写的key和T都是两个结构体。

使用insertMulti

 1>  main.cpp
1>d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(111): error C2665: “qHash”: 17 个重载中没有一个可以转换所有参数类型
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(63): 可能是“uint qHash(char,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(64): 或       “uint qHash(uchar,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(65): 或       “uint qHash(signed char,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(66): 或       “uint qHash(ushort,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(67): 或       “uint qHash(short,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(68): 或       “uint qHash(uint,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(69): 或       “uint qHash(int,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(70): 或       “uint qHash(ulong,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(78): 或       “uint qHash(long,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(79): 或       “uint qHash(quint64,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(87): 或       “uint qHash(qint64,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(88): 或       “uint qHash(QChar,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(89): 或       “uint qHash(const QByteArray &,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(90): 或       “uint qHash(const QString &,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(91): 或       “uint qHash(const QStringRef &,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(92): 或       “uint qHash(const QBitArray &,uint) throw()”
1>          d:\qt\qt5.1.1\5.1.1\msvc2010\include\qtcore\qhash.h(93): 或       “uint qHash(QLatin1String,uint) throw()”
.
.
.
  • 写回答

2条回答 默认 最新

  • hair_man 2015-08-21 06:41
    关注

    也许是我的问题不正确,我现在已经得到答案了,在自己构建QMultiHash的时候,ket和t是结构体时。需要给key重载==运算符,并设置全局的qHash函数供系统使用。
    小例子以方便理解:
    重载==函数就不写了,主要就是对qHash这个全局函数进行重载,将结构体中的每个元素异或。

     typedef struct A_key
     {
                int a;
                char b;
                double c;
     }Akey;
    
     typedef struct A_t
     {
         int a;
     }At;
     QMultiHash<Akey, At> TwoStructHash;
    
     int qHash(const Akey& AkeyTemp)
     {
         return AkeyTemp.a ^ AkeyTemp.b ^ AkeyTemp.c;
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘