diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index 35c2622da..7fa78b233 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -90,9 +90,13 @@ BitTorrent::TorrentID BitTorrent::TorrentID::fromInfoHash(const BitTorrent::Info return infoHash.toTorrentID(); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t BitTorrent::qHash(const BitTorrent::TorrentID &key, const std::size_t seed) +#else uint BitTorrent::qHash(const BitTorrent::TorrentID &key, const uint seed) +#endif { - return ::qHash(std::hash()(key), seed); + return ::qHash(static_cast(key), seed); } bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent::InfoHash &right) diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index dc1ac6a67..f6f3101a1 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -32,6 +32,7 @@ #include #endif +#include #include #include @@ -81,7 +82,11 @@ namespace BitTorrent WrappedType m_nativeHash; }; - uint qHash(const TorrentID &key, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const TorrentID &key, std::size_t seed = 0); +#else + uint qHash(const TorrentID &key, uint seed = 0); +#endif bool operator==(const InfoHash &left, const InfoHash &right); bool operator!=(const InfoHash &left, const InfoHash &right); diff --git a/src/base/bittorrent/ltqhash.h b/src/base/bittorrent/ltqhash.h index ad0625c62..b8a929b32 100644 --- a/src/base/bittorrent/ltqhash.h +++ b/src/base/bittorrent/ltqhash.h @@ -28,23 +28,24 @@ #pragma once +#include + +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #include #include #include -// From https://doc.qt.io/qt-6/qhash.html#the-hashing-function: -// A hashing function for a key type K may be provided in two different ways. -// The first way is by having an overload of qHash() in K's namespace. namespace libtorrent { namespace aux { template - uint qHash(const strong_typedef &key, const uint seed) + uint qHash(const strong_typedef &key, const uint seed = 0) { return ::qHash((std::hash> {})(key), seed); } } } +#endif diff --git a/src/base/bittorrent/peeraddress.cpp b/src/base/bittorrent/peeraddress.cpp index ebe73d637..3785bfbf5 100644 --- a/src/base/bittorrent/peeraddress.cpp +++ b/src/base/bittorrent/peeraddress.cpp @@ -77,7 +77,14 @@ bool BitTorrent::operator==(const BitTorrent::PeerAddress &left, const BitTorren return (left.ip == right.ip) && (left.port == right.port); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t BitTorrent::qHash(const BitTorrent::PeerAddress &addr, const std::size_t seed) +{ + return qHashMulti(seed, addr.ip, addr.port); +} +#else uint BitTorrent::qHash(const BitTorrent::PeerAddress &addr, const uint seed) { return (::qHash(addr.ip, seed) ^ ::qHash(addr.port)); } +#endif diff --git a/src/base/bittorrent/peeraddress.h b/src/base/bittorrent/peeraddress.h index 3d7e5b391..9f1e7d0a7 100644 --- a/src/base/bittorrent/peeraddress.h +++ b/src/base/bittorrent/peeraddress.h @@ -28,6 +28,7 @@ #pragma once +#include #include class QString; @@ -44,5 +45,9 @@ namespace BitTorrent }; bool operator==(const PeerAddress &left, const PeerAddress &right); - uint qHash(const PeerAddress &addr, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const PeerAddress &addr, std::size_t seed = 0); +#else + uint qHash(const PeerAddress &addr, uint seed = 0); +#endif } diff --git a/src/base/bittorrent/torrent.cpp b/src/base/bittorrent/torrent.cpp index 700011461..e478eabfd 100644 --- a/src/base/bittorrent/torrent.cpp +++ b/src/base/bittorrent/torrent.cpp @@ -35,7 +35,11 @@ namespace BitTorrent { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const TorrentState key, const std::size_t seed) +#else uint qHash(const TorrentState key, const uint seed) +#endif { return ::qHash(static_cast>(key), seed); } diff --git a/src/base/bittorrent/torrent.h b/src/base/bittorrent/torrent.h index 526255b88..453013233 100644 --- a/src/base/bittorrent/torrent.h +++ b/src/base/bittorrent/torrent.h @@ -29,6 +29,7 @@ #pragma once +#include #include #include #include @@ -97,7 +98,11 @@ namespace BitTorrent Error }; - uint qHash(TorrentState key, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(TorrentState key, std::size_t seed = 0); +#else + uint qHash(TorrentState key, uint seed = 0); +#endif class Torrent : public AbstractFileStorage { diff --git a/src/base/bittorrent/tracker.cpp b/src/base/bittorrent/tracker.cpp index 0c6f35ec3..a811502ec 100644 --- a/src/base/bittorrent/tracker.cpp +++ b/src/base/bittorrent/tracker.cpp @@ -140,7 +140,11 @@ namespace BitTorrent return !(left == right); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const Peer &key, const std::size_t seed) +#else uint qHash(const Peer &key, const uint seed) +#endif { return qHash(key.uniqueID(), seed); } diff --git a/src/base/bittorrent/tracker.h b/src/base/bittorrent/tracker.h index 2d007961e..6e502c075 100644 --- a/src/base/bittorrent/tracker.h +++ b/src/base/bittorrent/tracker.h @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -64,7 +65,11 @@ namespace BitTorrent bool operator==(const Peer &left, const Peer &right); bool operator!=(const Peer &left, const Peer &right); - uint qHash(const Peer &key, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const Peer &key, std::size_t seed = 0); +#else + uint qHash(const Peer &key, uint seed = 0); +#endif // *Basic* Bittorrent tracker implementation // [BEP-3] The BitTorrent Protocol Specification diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index 622678022..679029317 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/src/base/bittorrent/trackerentry.cpp @@ -36,7 +36,14 @@ bool BitTorrent::operator==(const TrackerEntry &left, const TrackerEntry &right) && QUrl(left.url) == QUrl(right.url)); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t BitTorrent::qHash(const TrackerEntry &key, const std::size_t seed) +{ + return qHashMulti(seed, key.url, key.tier); +} +#else uint BitTorrent::qHash(const TrackerEntry &key, const uint seed) { return (::qHash(key.url, seed) ^ ::qHash(key.tier)); } +#endif diff --git a/src/base/bittorrent/trackerentry.h b/src/base/bittorrent/trackerentry.h index ede17cb52..61649fd7b 100644 --- a/src/base/bittorrent/trackerentry.h +++ b/src/base/bittorrent/trackerentry.h @@ -71,5 +71,9 @@ namespace BitTorrent }; bool operator==(const TrackerEntry &left, const TrackerEntry &right); - uint qHash(const TrackerEntry &key, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const TrackerEntry &key, std::size_t seed = 0); +#else + uint qHash(const TrackerEntry &key, uint seed = 0); +#endif } diff --git a/src/base/digest32.h b/src/base/digest32.h index bf007f9d3..111f82e60 100644 --- a/src/base/digest32.h +++ b/src/base/digest32.h @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -130,8 +131,16 @@ bool operator<(const Digest32 &left, const Digest32 &right) < static_cast::UnderlyingType>(right); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) template -uint qHash(const Digest32 &key, const uint seed) +std::size_t qHash(const Digest32 &key, const std::size_t seed = 0) { - return ::qHash(std::hash::UnderlyingType>()(key), seed); + return ::qHash(static_cast::UnderlyingType>(key), seed); } +#else +template +uint qHash(const Digest32 &key, const uint seed = 0) +{ + return static_cast((std::hash::UnderlyingType> {})(key)) ^ seed; +} +#endif diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index 2a348e079..872fcaecf 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -364,10 +364,17 @@ Net::ServiceID Net::ServiceID::fromURL(const QUrl &url) return {url.host(), url.port(80)}; } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t Net::qHash(const ServiceID &serviceID, const std::size_t seed) +{ + return qHashMulti(seed, serviceID.hostName, serviceID.port); +} +#else uint Net::qHash(const ServiceID &serviceID, const uint seed) { return ::qHash(serviceID.hostName, seed) ^ ::qHash(serviceID.port); } +#endif bool Net::operator==(const ServiceID &lhs, const ServiceID &rhs) { diff --git a/src/base/net/downloadmanager.h b/src/base/net/downloadmanager.h index 2dea1c162..32fcab175 100644 --- a/src/base/net/downloadmanager.h +++ b/src/base/net/downloadmanager.h @@ -29,6 +29,7 @@ #pragma once +#include #include #include #include @@ -52,7 +53,11 @@ namespace Net static ServiceID fromURL(const QUrl &url); }; - uint qHash(const ServiceID &serviceID, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + std::size_t qHash(const ServiceID &serviceID, std::size_t seed = 0); +#else + uint qHash(const ServiceID &serviceID, uint seed = 0); +#endif bool operator==(const ServiceID &lhs, const ServiceID &rhs); enum class DownloadStatus diff --git a/src/base/path.cpp b/src/base/path.cpp index da7881993..a7675fb68 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -332,7 +332,11 @@ QDataStream &operator>>(QDataStream &in, Path &path) return in; } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t qHash(const Path &key, const std::size_t seed) +#else uint qHash(const Path &key, const uint seed) +#endif { return ::qHash(key.data(), seed); } diff --git a/src/base/path.h b/src/base/path.h index 614ba640f..fb2b97c2f 100644 --- a/src/base/path.h +++ b/src/base/path.h @@ -29,6 +29,7 @@ #pragma once +#include #include #include @@ -96,4 +97,8 @@ Path operator+(const Path &lhs, const std::string &rhs); QDataStream &operator<<(QDataStream &out, const Path &path); QDataStream &operator>>(QDataStream &in, Path &path); -uint qHash(const Path &key, uint seed); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t qHash(const Path &key, std::size_t seed = 0); +#else +uint qHash(const Path &key, uint seed = 0); +#endif diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 276fda56a..96d81008d 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -70,10 +71,17 @@ bool operator==(const PeerEndpoint &left, const PeerEndpoint &right) return (left.address == right.address) && (left.connectionType == right.connectionType); } -uint qHash(const PeerEndpoint &peerEndpoint, const uint seed) +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +std::size_t qHash(const PeerEndpoint &peerEndpoint, const std::size_t seed = 0) +{ + return qHashMulti(seed, peerEndpoint.address, peerEndpoint.connectionType); +} +#else +uint qHash(const PeerEndpoint &peerEndpoint, const uint seed = 0) { return (qHash(peerEndpoint.address, seed) ^ ::qHash(peerEndpoint.connectionType)); } +#endif PeerListWidget::PeerListWidget(PropertiesWidget *parent) : QTreeView(parent)