- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想创建一个 QSet<Tag>
我想在我的程序中使用。 Tag
是我的自定义类。
当我构建代码时,我得到关于 qHash
的 gcc 错误重载:
Exercise.cpp.o
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qglobal.h:74:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/qchar.h:37,
from /opt/Qt/5.5/gcc_64/include/QtCore/qstring.h:41,
from /opt/Qt/5.5/gcc_64/include/QtCore/QString:1,
from /src/wmathtest/LaTeXText.h:4,
from /src/wmathtest/Exercise.h:4,
from /src/wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h: In instantiation of ‘uint qHash(const T&, uint) [with T = WMathTest::Tag; uint = unsigned int]’:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:952:32: required from ‘QHash<Key, T>::Node** QHash<Key, T>::findNode(const Key&, uint*) const [with Key = WMathTest::Tag; T = QHashDummyValue; QHash<Key, T>::Node = QHashNode<WMathTest::Tag, QHashDummyValue>; uint = unsigned int]’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:808:36: required from ‘QHash<Key, T>::iterator QHash<Key, T>::insert(const Key&, const T&) [with Key = WMathTest::Tag; T = QHashDummyValue]’
/opt/Qt/5.5/gcc_64/include/QtCore/qset.h:188:94: required from ‘QSet<T>::iterator QSet<T>::insert(const T&) [with T = WMathTest::Tag]’
/src/wmathtest/Exercise.cpp:22:22: required from here
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:103:5: error: no matching function for call to ‘qHash(const WMathTest::Tag&)’
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:103:5: note: candidates are:
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qset.h:37:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/QSet:1,
from /src/wmathtest/Tag.h:5,
from /src/wmathtest/Exercise.h:5,
from /src/wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:65:52: note: constexpr uint qHash(char, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:65:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘char’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:66:52: note: constexpr uint qHash(uchar, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uchar key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:66:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘uchar {aka unsigned char}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:67:52: note: constexpr uint qHash(signed char, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(signed char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:67:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘signed char’
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qset.h:37:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/QSet:1,
from /src/wmathtest/Tag.h:5,
from /src/wmathtest/Exercise.h:5,
from /src/wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:68:52: note: constexpr uint qHash(ushort, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ushort key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:68:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘ushort {aka short unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:69:52: note: constexpr uint qHash(short int, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(short key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:69:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘short int’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:70:52: note: constexpr uint qHash(uint, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uint key, uint seed = 0) Q_DECL_NOTHROW { return key ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:70:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘uint {aka unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:71:52: note: constexpr uint qHash(int, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(int key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:71:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘int’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:72:52: note: constexpr uint qHash(ulong, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ulong key, uint seed = 0) Q_DECL_NOTHROW
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:72:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘ulong {aka long unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:78:52: note: constexpr uint qHash(long int, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(long key, uint seed = 0) Q_DECL_NOTHROW { return qHash(ulong(key), seed); }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:78:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘long int’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:79:52: note: constexpr uint qHash(quint64, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(quint64 key, uint seed = 0) Q_DECL_NOTHROW
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:79:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘quint64 {aka long long unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:83:52: note: constexpr uint qHash(qint64, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) Q_DECL_NOTHROW { return qHash(quint64(key), seed); }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:83:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘qint64 {aka long long int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:84:42: note: uint qHash(float, uint)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:84:42: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘float’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:85:42: note: uint qHash(double, uint)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:85:42: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘double’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:87:42: note: uint qHash(long double, uint)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:87:42: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘long double’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:89:52: note: constexpr uint qHash(QChar, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) Q_DECL_NOTHROW { return qHash(key.unicode(), seed); }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:89:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘QChar’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:90:41: note: uint qHash(const QByteArray&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:90:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QByteArray&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:91:41: note: uint qHash(const QString&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:91:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QString&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:92:41: note: uint qHash(const QStringRef&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:92:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QStringRef&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:93:41: note: uint qHash(const QBitArray&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:93:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QBitArray&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:94:41: note: uint qHash(QLatin1String, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:94:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘QLatin1String’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:98:32: note: template<class T> uint qHash(const T*, uint)
template <class T> inline uint qHash(const T *key, uint seed = 0) Q_DECL_NOTHROW
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:98:32: note: template argument deduction/substitution failed:
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qglobal.h:74:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/qchar.h:37,
from /opt/Qt/5.5/gcc_64/include/QtCore/qstring.h:41,
from /opt/Qt/5.5/gcc_64/include/QtCore/QString:1,
from /src/wmathtest/LaTeXText.h:4,
from /src/wmathtest/Exercise.h:4,
from /src/wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:103:5: note: mismatched types ‘const T*’ and ‘WMathTest::Tag’
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
^
src/wmathtest/CMakeFiles/wmathtest.dir/build.make:146: recipe for target 'src/wmathtest/CMakeFiles/wmathtest.dir/Exercise.cpp.o' failed
make[2]: *** [src/wmathtest/CMakeFiles/wmathtest.dir/Exercise.cpp.o] Error 1
CMakeFiles/Makefile2:160: recipe for target 'src/wmathtest/CMakeFiles/wmathtest.dir/all' failed
make[1]: *** [src/wmathtest/CMakeFiles/wmathtest.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
Exercise.cpp.o
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qglobal.h:74:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/qchar.h:37,
from /opt/Qt/5.5/gcc_64/include/QtCore/qstring.h:41,
from /opt/Qt/5.5/gcc_64/include/QtCore/QString:1,
from /wmathtest/LaTeXText.h:4,
from /src/wmathtest/Exercise.h:4,
from /wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h: In instantiation of ‘uint qHash(const T&, uint) [with T = WMathTest::Tag; uint = unsigned int]’:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:952:32: required from ‘QHash<Key, T>::Node** QHash<Key, T>::findNode(const Key&, uint*) const [with Key = WMathTest::Tag; T = QHashDummyValue; QHash<Key, T>::Node = QHashNode<WMathTest::Tag, QHashDummyValue>; uint = unsigned int]’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:808:36: required from ‘QHash<Key, T>::iterator QHash<Key, T>::insert(const Key&, const T&) [with Key = WMathTest::Tag; T = QHashDummyValue]’
/opt/Qt/5.5/gcc_64/include/QtCore/qset.h:188:94: required from ‘QSet<T>::iterator QSet<T>::insert(const T&) [with T = WMathTest::Tag]’
/wmathtest/Exercise.cpp:22:22: required from here
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:103:5: error: no matching function for call to ‘qHash(const WMathTest::Tag&)’
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:103:5: note: candidates are:
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qset.h:37:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/QSet:1,
from /wmathtest/Tag.h:5,
from /wmathtest/Exercise.h:5,
from /wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:65:52: note: constexpr uint qHash(char, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:65:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘char’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:66:52: note: constexpr uint qHash(uchar, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uchar key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:66:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘uchar {aka unsigned char}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:67:52: note: constexpr uint qHash(signed char, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(signed char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:67:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘signed char’
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qset.h:37:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/QSet:1,
from /home/daniele/projects/wmathtestgenerator/src/wmathtest/Tag.h:5,
from /Exercise.h:5,
from /wmathtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:68:52: note: constexpr uint qHash(ushort, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ushort key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:68:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘ushort {aka short unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:69:52: note: constexpr uint qHash(short int, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(short key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:69:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘short int’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:70:52: note: constexpr uint qHash(uint, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uint key, uint seed = 0) Q_DECL_NOTHROW { return key ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:70:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘uint {aka unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:71:52: note: constexpr uint qHash(int, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(int key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:71:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘int’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:72:52: note: constexpr uint qHash(ulong, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ulong key, uint seed = 0) Q_DECL_NOTHROW
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:72:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘ulong {aka long unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:78:52: note: constexpr uint qHash(long int, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(long key, uint seed = 0) Q_DECL_NOTHROW { return qHash(ulong(key), seed); }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:78:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘long int’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:79:52: note: constexpr uint qHash(quint64, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(quint64 key, uint seed = 0) Q_DECL_NOTHROW
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:79:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘quint64 {aka long long unsigned int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:83:52: note: constexpr uint qHash(qint64, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) Q_DECL_NOTHROW { return qHash(quint64(key), seed); }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:83:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘qint64 {aka long long int}’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:84:42: note: uint qHash(float, uint)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:84:42: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘float’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:85:42: note: uint qHash(double, uint)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:85:42: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘double’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:87:42: note: uint qHash(long double, uint)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:87:42: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘long double’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:89:52: note: constexpr uint qHash(QChar, uint)
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) Q_DECL_NOTHROW { return qHash(key.unicode(), seed); }
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:89:52: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘QChar’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:90:41: note: uint qHash(const QByteArray&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:90:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QByteArray&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:91:41: note: uint qHash(const QString&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:91:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QString&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:92:41: note: uint qHash(const QStringRef&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:92:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QStringRef&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:93:41: note: uint qHash(const QBitArray&, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:93:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘const QBitArray&’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:94:41: note: uint qHash(QLatin1String, uint)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) Q_DECL_NOTHROW;
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:94:41: note: no known conversion for argument 1 from ‘const WMathTest::Tag’ to ‘QLatin1String’
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:98:32: note: template<class T> uint qHash(const T*, uint)
template <class T> inline uint qHash(const T *key, uint seed = 0) Q_DECL_NOTHROW
^
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:98:32: note: template argument deduction/substitution failed:
In file included from /opt/Qt/5.5/gcc_64/include/QtCore/qglobal.h:74:0,
from /opt/Qt/5.5/gcc_64/include/QtCore/qchar.h:37,
from /opt/Qt/5.5/gcc_64/include/QtCore/qstring.h:41,
from /opt/Qt/5.5/gcc_64/include/QtCore/QString:1,
from /home/daniele/projects/wmathtestgenerator/src/wmathtest/LaTeXText.h:4,
from /home/daniele/projects/wmathtestgenerator/src/wmathtest/Exercise.h:4,
from /thtest/Exercise.cpp:1:
/opt/Qt/5.5/gcc_64/include/QtCore/qhash.h:103:5: note: mismatched types ‘const T*’ and ‘WMathTest::Tag’
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
^
src/wmathtest/CMakeFiles/wmathtest.dir/build.make:146: recipe for target 'src/wmathtest/CMakeFiles/wmathtest.dir/Exercise.cpp.o' failed
make[2]: *** [src/wmathtest/CMakeFiles/wmathtest.dir/Exercise.cpp.o] Error 1
CMakeFiles/Makefile2:160: recipe for target 'src/wmathtest/CMakeFiles/wmathtest.dir/all' failed
make[1]: *** [src/wmathtest/CMakeFiles/wmathtest.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
我已经创建了类 operator==
和 qHash
为类(class)。然后我创建了一个 typedef
对于类(class),但这不起作用。
我做错了什么?
标签.h
#ifndef WMATHTEST_TAG_H_
#define WMATHTEST_TAG_H_
#include <QString>
#include <QSet>
namespace WMathTest {
class Tag {
public:
Tag() = default;
Tag(const QString &text);
Tag(const Tag &tag) = default;
virtual ~Tag() = default;
void setText(const QString &text);
const QString& getText() const;
bool operator==(const Tag &other);
private:
QString m_text;
};
} // namespace WMathTest
inline uint qHash(const WMathTest::Tag &tag, uint seed) {
return qHash(tag.getText(), seed);
}
typedef QSet<WMathTest::Tag> TagList;
#endif // !WMATHTEST_TAG_H_
标签.cpp
#include "wmathtest/Tag.h"
namespace WMathTest {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
Tag::Tag(const QString &text) :
m_text(text) {
}
void Tag::setText(const QString &text) {
m_text = text;
}
const QString& Tag::getText() const {
return m_text;
}
bool Tag::operator==(const Tag &other) {
return m_text == other.m_text;
}
} // namespace WMathTest
练习.h
#ifndef WMATHTEST_EXERCISE_H_
#define WMATHTEST_EXERCISE_H_
#include "wmathtest/LaTeXText.h"
#include "wmathtest/Tag.h"
#include <QString>
namespace WMathTest {
class Exercise {
public:
Exercise() = default;
virtual ~Exercise() = default;
void setID(const QString &id);
void setProblem(const LaTeXText &problem);
void setSolution(const LaTeXText &solution);
void addArgumentTag(const Tag &tag);
void addArgumentTag(const QString &tag);
QString getID() const;
LaTeXText getProblem() const;
LaTeXText getSolution() const;
const TagList& getArgumentTagList() const;
private:
QString m_id;
LaTeXText m_problem;
LaTeXText m_solution;
TagList m_tagList;
};
} // namespace WMathTest
#endif // !WMATHTEST_EXERCISE_H_
练习.cpp
#include "wmathtest/Exercise.h"
namespace WMathTest {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
void Exercise::setID(const QString &id) {
m_id = id;
}
void Exercise::setProblem(const LaTeXText &problem) {
m_problem = problem;
}
void Exercise::setSolution(const LaTeXText &solution) {
m_solution = solution;
}
void Exercise::addArgumentTag(const Tag &tag) {
m_tagList.insert(tag);
}
void Exercise::addArgumentTag(const QString &tag) {
m_tagList.insert(Tag(tag));
}
QString Exercise::getID() const {
return m_id;
}
LaTeXText Exercise::getProblem() const {
return m_problem;
}
LaTeXText Exercise::getSolution() const {
return m_solution;
}
const TagList& Exercise::getArgumentTagList() const {
return m_tagList;
}
} // namespace WMathTest
最佳答案
散列是一个一元函数(只有一个参数),它是数学意义上的函数(对特定参数返回相同的值,并将对完整的参数集返回有效值)。
哈希函数有一个必须始终满足才能正常工作的重要条件:如果两个对象被认为是相等的,那么该对象的哈希值也必须相等。因此,例如,如果您在不区分大小写的容器中使用字符串作为键,则必须提供不区分大小写的哈希函数。
请注意 qHash functions you are see in documentation 的附加参数: seed
总是有一个默认值!所以这个函数可以用单个参数调用!此参数只是一个选项,让您有机会在为复杂类型构建自定义哈希函数时调整哈希函数。
像这样修复你的代码:
inline uint qHash(const WMathTest::Tag &tag) {
return qHash(tag.getText(), 0xa03f); // arbitrary value
}
或者像这样:
inline uint qHash(const WMathTest::Tag &tag, uint seed = 0) {
return qHash(tag.getText(), seed^0xa03f);
}
在更复杂类型的情况下,哈希函数可能如下所示(示例为什么种子有用):
inline uint qHash(const DoubleStringValue &tag, uint seed = 0) {
return qHash(tag.firstText(), seed^0xa03f)^qHash(tag.secondText(), seed^0x17a317a3);
}
请注意,如果有两个 DoubleStringValue
对象,其中 firstText
和 secondText
被翻转,则它们的哈希值将不同.
我建议阅读一些文档,了解带有哈希函数的容器如何工作,以及为什么它们比其他解决方案(例如红黑树)更快。
关于c++ - QSet:qHash 和自定义类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32617181/
有没有办法设置 QSettings 存储的实际默认路径(有或没有文件名),并防止 QSettings 将组织名称等内容附加到该路径?这要求 QSettings 的进一步使用保持不变并且不知道设置存储路
你好,我有一个由应用程序生成的 Mac OS X plist 文件 (QSetting::NativeFormat),现在我想在不支持它的基于 Linux 的操作系统上使用这个 plist 文件。所以
Qt 错误报告链接:QTBUG-53313 从 Qt 5.5 迁移到 Qt 5.6 会出现一个问题 QSettings它在系统范围内找不到 QSettings 配置文件。在下面的 main.cpp 中
我程序里的设置挺多的,大概有3000个。它们不应该在程序开始时立即阅读,而是在需要时在程序的 10 个不同位置阅读。我想知道执行此操作的在性能/内存使用方面最有效的方法是什么: 1 始终打开一个“全局
我想用QSettings保存高分,但它不能正常工作。我在 2 个不同的文件中保存和读取这些值。 这是我负责将值添加到数组中的代码: QSettings settings; settings.begin
我从某个位置上传文件,然后下一次上传必须指向上次上传的位置。 我怎样才能使用 QSettings 来实现? ? 最佳答案 在使用 QSettings 之前,我建议在您的 main() 中设置一些有关您
我有 ini 格式的 QSettings 对象。 当我在 ini 文件中写入 settings.beginGroup("GENERAL") 时,我看到以下内容: [%常规] 为什么会这样? 最佳答案
我正在尝试为 QSettings 创建自定义格式,但无法从存储中读取它。 在下面的代码中,如果我运行 settings.setValue("test", 123") ,它会正确调用 write 函数并
我正在使用QSettings在Windows中将某些数据存储为ini文件。 我想查看ini文件,但我不知道ini文件的位置。 这是我的代码: QSettings *set = new QSetting
我使用 QSettings 来编辑 .desktop 菜单条目。我这样做: dfile 是一个 QString - 绝对文件路径 QSettings set(dfile, QSettings::Ini
我正在尝试在我的代码中使用 QSettings,但它无法正常工作。我的代码是: In Mainwindow.h QSettings settings (我已经在所有setOrganizationNam
我正在使用非图形用户界面产品的 Qsettings 将其设置存储到 xml 文件中。这是作为一个库编写的,可在 C、C++ 程序中使用。每个产品将有 1 个 xml 文件。每个产品可能有多个子产品,它
我想知道为什么这段基于虚假公司名称和应用程序名称创建 Qt 设置实例的代码不起作用。 这里是mainwindow.h,还有一个main.cpp,还有mainwindow.cpp,一个.pro文件,.u
我正在使用 Qsetting 来存储上次使用的值。我的代码只适用于一个领域。这意味着当我为第二轮应用相同的逻辑时它只工作一次,但它不会那样做。 文件io.cpp #include "fileio.h"
Does Qt has something like QSettings, but for local scopes? 我正在寻找具有相同方法但不特定于 APPLICATION 的数据结构。 我的意思
QSettings settings("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",QSettings::Nati
有没有办法使用 QSettings 为每个键存储多个值,并将其存储在人类可读(无二进制文件).ini 文件中? 可能看起来像: key_1=value_1,value2 key_2=value_1 .
我正在尝试为我的 Qt 应用程序实现应用程序设置。我正在使用 QSettings ,像这样创建了我的类的实例 settings = new QSettings(qApp->organizationNa
我正在使用 QSettings 编写一个 .ini 文件,它将作为我的应用程序配置文件。只有一个问题: QSettings 将组名 [General] 添加到文件的顶部。 我这样设置文件: QSett
我编写了一个简单的应用程序来使用 QSettings。谁能告诉我我在这里做错了什么.. 主窗口.h class MainWindow : public QMainWindow { Q_OBJE
我是一名优秀的程序员,十分优秀!