首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QSet不让我添加我自己的类型

QSet不让我添加我自己的类型
EN

Stack Overflow用户
提问于 2011-04-08 17:33:28
回答 1查看 1.5K关注 0票数 2

我使用的是QT,我有一个QSet,希望将vtkSmartPointer<vtkImageData>添加到其中。我的语法是QSet<vtkSmartPointer<vtkImageData> >。但是,我得到了以下编译错误。

代码语言:javascript
复制
c:\qt\4.7.2\include\qtcore\..\..\src\corelib\tools\qhash.h:880: error: C2665: 'qHash' : none of the 16 overloads could convert all the argument types
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(62): could be 'uint qHash(char)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(63): or       'uint qHash(uchar)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(64): or       'uint qHash(signed char)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(65): or       'uint qHash(ushort)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(66): or       'uint qHash(short)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(67): or       'uint qHash(uint)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(68): or       'uint qHash(int)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(69): or       'uint qHash(ulong)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(77): or       'uint qHash(long)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(78): or       'uint qHash(quint64)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(86): or       'uint qHash(qint64)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(87): or       'uint qHash(QChar)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(88): or       'uint qHash(const QByteArray &)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(89): or       'uint qHash(const QString &)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(90): or       'uint qHash(const QStringRef &)'
c:\qt\4.7.2\include\qtcore\../../src/corelib/tools/qhash.h(91): or       'uint qHash(const QBitArray &)'

同时尝试将参数列表'(const vtkSmartPointer)‘与

代码语言:javascript
复制
[
    T=vtkImageData
]

在我看来,这似乎是我必须编写我自己的散列函数。

  1. 是对的吗?
  2. ,如果是的话,我该怎么做?
  3. ,如果不是发生了什么?

我是来自Java的QT新手,在那里我从来不用担心编写自己的散列函数。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-08 17:55:43

您是正确的,因为您必须为vtkSmartPointer类编写自己的散列函数,因为Qt不提供哈希函数。然而,Qt确实为指针(qHash(const T *))提供了一个散列函数,因此您可以尝试如下所示:

代码语言:javascript
复制
template<typename T>
uint qHash(const vtkSmartPointer<T> &p)
{
    return qHash(p.GetPointer());
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5598700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档