From 31edf30c619213368e9b592b51be6ca8190db831 Mon Sep 17 00:00:00 2001 From: Shane Ringrose Date: Sun, 21 Jun 2026 22:08:11 +1200 Subject: [PATCH] Fix #391: use wide-char path for pugixml on Windows to handle Unicode paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pugi::xml_document::load_file(const char*) calls fopen/fopen_s on Windows, which uses the ANSI codepage — not UTF-8. This silently fails when the collection path contains accented characters (é, ü, ñ, …) or is longer than the narrow-API MAX_PATH limit, leaving the collection panel with no element names or illustrations. Switch both call sites to toStdWString().c_str() which invokes the load_file(const wchar_t*) overload. On Windows pugixml calls _wfopen, the wide Unicode API that handles all valid Unicode paths. On Linux/macOS the same overload converts wchar_t to UTF-8 internally and calls fopen, so behaviour is unchanged on those platforms. Affected files: sources/ElementsCollection/fileelementcollectionitem.cpp (qet_directory load) sources/ElementsCollection/elementslocation.cpp (element .elmt load, both branches) Co-Authored-By: Claude Sonnet 4.6 --- sources/ElementsCollection/elementslocation.cpp | 4 ++-- sources/ElementsCollection/fileelementcollectionitem.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sources/ElementsCollection/elementslocation.cpp b/sources/ElementsCollection/elementslocation.cpp index c14f244ff..f8cd34707 100644 --- a/sources/ElementsCollection/elementslocation.cpp +++ b/sources/ElementsCollection/elementslocation.cpp @@ -701,11 +701,11 @@ pugi::xml_document ElementsLocation::pugiXml() const if (!m_project) { #ifndef Q_OS_LINUX - if (docu.load_file(m_file_system_path.toStdString().c_str())) { + if (docu.load_file(m_file_system_path.toStdWString().c_str())) { docu.save(m_string_stream); } #else - docu.load_file(m_file_system_path.toStdString().c_str()); + docu.load_file(m_file_system_path.toStdWString().c_str()); #endif } else diff --git a/sources/ElementsCollection/fileelementcollectionitem.cpp b/sources/ElementsCollection/fileelementcollectionitem.cpp index 5f42efec4..7f8c35f78 100644 --- a/sources/ElementsCollection/fileelementcollectionitem.cpp +++ b/sources/ElementsCollection/fileelementcollectionitem.cpp @@ -138,7 +138,7 @@ QString FileElementCollectionItem::localName() { QString str(fileSystemPath() % "/qet_directory"); pugi::xml_document docu; - if(docu.load_file(str.toStdString().c_str())) + if(docu.load_file(str.toStdWString().c_str())) { if (QString(docu.document_element().name()) == "qet-directory")