Skip to content

Commit

Permalink
Workaround what appear to be QStringConverter bugs
Browse files Browse the repository at this point in the history
* Data modification when using QStringConverter::encodingForData
  (QTBUG-87466)

* Crash when calling QStringDecoder::decode (not reported yet, unsure
  what causes it).

For now we assume scripts are saved as UTF-8 when compiling against
Qt 6.
  • Loading branch information
bjorn committed Oct 13, 2020
1 parent c8dc697 commit 238186a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/tiled/scriptmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ QJSValue ScriptManager::evaluateFile(const QString &fileName)
if (!fromUtf8(bytes, script))
script = QTextCodec::codecForUtfText(bytes)->toUnicode(bytes);
#else
auto encoding = QStringConverter::encodingForData(bytes.constData(), bytes.size());
QStringDecoder decoder(encoding.value_or(QStringConverter::Encoding::Utf8));
script = decoder.decode(bytes);
if (decoder.hasError()) {
Tiled::ERROR(tr("Error decoding file: %1").arg(fileName));
return QJSValue();
}
// Workaround for Qt 6.0 Alpha bug (QTBUG-87466)
// auto encoding = QStringConverter::encodingForData(bytes.constData(), bytes.size());
// QStringDecoder decoder(encoding.value_or(QStringConverter::Encoding::Utf8));
// script = decoder.decode(bytes);
// if (decoder.hasError()) {
// Tiled::ERROR(tr("Error decoding file: %1").arg(fileName));
// return QJSValue();
// }
script = QString::fromUtf8(bytes);
#endif

Tiled::INFO(tr("Evaluating '%1'").arg(fileName));
Expand Down

0 comments on commit 238186a

Please sign in to comment.