From b2eb29ab5d1a0546ab9a12b3079723c2661c0403 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 26 Oct 2024 19:38:04 +0800 Subject: [PATCH] lyricsmanager: parse time string by ourselves QTime::fromString() can lead a crash when build with icu-enabled Qt 6.8.0, see QTBUG-130597. Anyway let's workaround this issue by simply implement it by ourselves. --- lyricsmanager.cpp | 20 ++++++++++++++++++-- lyricsmanager.h | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lyricsmanager.cpp b/lyricsmanager.cpp index fd02a6b..f336ce2 100644 --- a/lyricsmanager.cpp +++ b/lyricsmanager.cpp @@ -112,8 +112,7 @@ bool LyricsManager::loadLyrics(QString filepath) QRegularExpressionMatch match = lrcRegex.match(line); while (match.hasMatch()) { tagSectionPassed = true; - QTime timestamp(QTime::fromString(match.captured(1), "m:s.zz")); - timestamps.append(timestamp.msecsSinceStartOfDay()); + timestamps.append(parseTimeToMilliseconds(match.captured(1))); currentLrc = match.captured(2); match = lrcRegex.match(currentLrc); } @@ -177,6 +176,23 @@ double LyricsManager::maskPercent(int curTimeMs) return (double)(curTimeMs - currentLyricsTime()) / (m_nextLyricsTime - m_currentLyricsTime); } +int LyricsManager::parseTimeToMilliseconds(const QString &timeString) +{ + QRegularExpression timeRegex(R"((\d{2,3}):(\d{2})\.(\d{2,3}))"); + QRegularExpressionMatch match = timeRegex.match(timeString); + + if (match.hasMatch()) { + int minutes = match.captured(1).toInt(); + int seconds = match.captured(2).toInt(); + int milliseconds = match.captured(3).toInt(); + + return minutes * 60000 + seconds * 1000 + milliseconds; + } else { + qCWarning(lcLyricsParser) << "Invalid time format:" << timeString; + return -1; + } +} + void LyricsManager::reset() { m_currentLyricsTime = 0; diff --git a/lyricsmanager.h b/lyricsmanager.h index fc24300..5383fd1 100644 --- a/lyricsmanager.h +++ b/lyricsmanager.h @@ -25,6 +25,8 @@ public: QString lyrics(int lineOffset = 0) const; double maskPercent(int curTimeMs); + static int parseTimeToMilliseconds(const QString& timeString); + protected: