From 0bae2b14b10cc1086511716244f0d01defc38328 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 5 Oct 2025 23:40:17 +0200 Subject: [PATCH] Do not implicitly convert QByteArray to const char* Operators supporting this conversion can be disabled via QT_NO_CAST_FROM_BYTEARRAY breaking the build. For example: https://koschei.fedoraproject.org//package/openmw https://kojipkgs.fedoraproject.org/work/tasks/5096/137735096/build.log --- apps/opencs/model/world/nestedtableproxymodel.cpp | 4 +++- apps/opencs/view/world/util.cpp | 4 ++-- components/files/qtconversion.cpp | 11 ++++++----- components/vfs/qtconversion.cpp | 11 ++++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/opencs/model/world/nestedtableproxymodel.cpp b/apps/opencs/model/world/nestedtableproxymodel.cpp index f542ce4def..5278710e4a 100644 --- a/apps/opencs/model/world/nestedtableproxymodel.cpp +++ b/apps/opencs/model/world/nestedtableproxymodel.cpp @@ -13,7 +13,9 @@ CSMWorld::NestedTableProxyModel::NestedTableProxyModel( { const int parentRow = parent.row(); - mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8()); + const QByteArray utf8 = parentModel->index(parentRow, 0).data().toString().toUtf8(); + + mId = std::string(utf8.constData(), utf8.size()); QAbstractProxyModel::setSourceModel(parentModel); diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 39b8ba321e..ae815f207c 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -362,8 +362,8 @@ void CSVWorld::CommandDelegate::setEditorData(QWidget* editor, const QModelIndex if (!n.isEmpty()) { if (!variant.isValid()) - variant = QVariant(editor->property(n).metaType(), (const void*)nullptr); - editor->setProperty(n, variant); + variant = QVariant(editor->property(n.constData()).metaType(), (const void*)nullptr); + editor->setProperty(n.constData(), variant); } } diff --git a/components/files/qtconversion.cpp b/components/files/qtconversion.cpp index d56832cb78..ac7ca6ec8b 100644 --- a/components/files/qtconversion.cpp +++ b/components/files/qtconversion.cpp @@ -1,8 +1,9 @@ - #include "qtconversion.hpp" #include +#include + QString Files::pathToQString(const std::filesystem::path& path) { const auto tmp = path.u8string(); @@ -17,12 +18,12 @@ QString Files::pathToQString(std::filesystem::path&& path) std::filesystem::path Files::pathFromQString(QStringView path) { - const auto tmp = path.toUtf8(); - return std::filesystem::path{ Misc::StringUtils::stringToU8String(tmp) }; + const QByteArray tmp = path.toUtf8(); + return std::filesystem::path(Misc::StringUtils::stringToU8String(std::string_view(tmp.constData(), tmp.size()))); } std::filesystem::path Files::pathFromQString(QString&& path) { - const auto tmp = path.toUtf8(); - return std::filesystem::path{ Misc::StringUtils::stringToU8String(tmp) }; + const QByteArray tmp = path.toUtf8(); + return std::filesystem::path(Misc::StringUtils::stringToU8String(std::string_view(tmp.constData(), tmp.size()))); } diff --git a/components/vfs/qtconversion.cpp b/components/vfs/qtconversion.cpp index 472e3dd0b4..fc8a0fb78e 100644 --- a/components/vfs/qtconversion.cpp +++ b/components/vfs/qtconversion.cpp @@ -1,8 +1,9 @@ - #include "qtconversion.hpp" #include +#include + QString VFS::Path::normalizedToQString(NormalizedView path) { return QString::fromUtf8(path.value().data(), path.value().size()); @@ -15,12 +16,12 @@ QString VFS::Path::normalizedToQString(Normalized&& path) VFS::Path::Normalized VFS::Path::normalizedFromQString(QStringView path) { - const auto tmp = path.toUtf8(); - return Normalized{ tmp }; + const QByteArray tmp = path.toUtf8(); + return Normalized(std::string_view(tmp.constData(), tmp.size())); } VFS::Path::Normalized VFS::Path::normalizedFromQString(QString&& path) { - const auto tmp = path.toUtf8(); - return Normalized{ tmp }; + const QByteArray tmp = std::move(path).toUtf8(); + return Normalized(std::string_view(tmp.constData(), tmp.size())); }