Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt 6: Fixed return value for qHash #3370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/tiled/id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,29 @@ class StringHash
{}

QByteArray string;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
uint hash;
#else
size_t hash;
#endif
};

static bool operator==(const StringHash &sh1, const StringHash &sh2)
{
return sh1.string == sh2.string;
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
static uint qHash(const StringHash &sh)
#else
static size_t qHash(const StringHash &sh)
#endif
{
return sh.hash;
}

static QHash<quintptr, StringHash> stringFromId;
static QHash<StringHash, quintptr> idFromString;
static QHash<uint, StringHash> stringFromId;
static QHash<StringHash, uint> idFromString;


Id::Id(const char *name)
Expand Down
10 changes: 7 additions & 3 deletions src/tiled/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#pragma once

#include <QDebug>
#include <QLatin1String>
#include <QMetaType>

Expand All @@ -45,13 +46,16 @@ class Id
private:
uint mId;

friend uint qHash(Id id) Q_DECL_NOTHROW;
friend auto qHash(Id id) Q_DECL_NOTHROW
{
return qHash(id.mId, 0);
}
};


inline uint qHash(Id id) Q_DECL_NOTHROW
inline QDebug operator<<(QDebug debug, Id id)
{
return id.mId;
return debug << id.name();
}

QStringList idsToNames(const QList<Id> &ids);
Expand Down