What is the best way to calculate the qHash value of a QRect? I need to use QRect (and maybe QRectF) as the key of QCache. Right now I am using something like this:
inline uint qHash(const QRect & r)
{
return qHash(QByteArray::fromRawData((const char*)&r, sizeof(r)));
}
It seems to work but I don't like casting it into some raw bytes and since QRect is noy a simple struct, this may break sooner than later in future versions of Qt.
BTW. I don't store the hash values so it doesn't have to be persistent or cross-platform. But it does need to be reliable and fast.
Thanks.
I would simply do return qHash(QString("%1,%2,%3,%4").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height())))
Also I've found this solution: http://thesmithfam.org/blog/2008/01/17/using-qrect-with-qhash/ (read comment)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With