Skip empty parts for stringToEnum template

metaEnum.keyToValue("") will results all flags get set, thus creating a
enum with empty (0) flags become impossible. This patch fixes that.
This commit is contained in:
Wang Zichong 2023-09-26 17:25:20 +08:00
parent 721c0ae334
commit 1573a89aac
1 changed files with 1 additions and 1 deletions

View File

@ -32,7 +32,7 @@ template<typename T>
T stringToEnum(QMetaEnum metaEnum, const QString &str) T stringToEnum(QMetaEnum metaEnum, const QString &str)
{ {
T ret = {}; T ret = {};
const auto splitted = str.split(QLatin1Char('|')); const auto splitted = str.split(QLatin1Char('|'), Qt::SkipEmptyParts);
for (const auto &value : splitted) { for (const auto &value : splitted) {
ret |= T(metaEnum.keyToValue(qPrintable(value))); ret |= T(metaEnum.keyToValue(qPrintable(value)));
} }