QDir::entryInfoList() not returning files with accents in Qt 5.10+
-
A Mac user of my rename software reported that files with accents in the name weren't showing up in the file list after I changed Qt version. Investigating the issue, I started to think it was a problem with
QDirin Qt 5.10+.I produced a simple program to display the output of
QDir::entryInfoList()in aQTextEdit. I sent him versions of this program built with Qt 5.9.0 and Qt 5.12.2. He tested the two builds with a directory containing ten files, half of which had accents in the name. When he runs the Qt 5.9.0 build all ten files show up:
However, only six files are returned by
QDir::entryInfoList()when he runs the Qt 5.12.2 build, and four of the files containing accents are missing:
This issue only happens on the user's computer. When I test on the Mac with the same ten files they all show up in all versions of Qt, as you can see in this screenshot. I wondered if it was an issue related to locale, so I changed my Region and Language to French, but I still couldn't recreate the problem.
The project for the test program can be downloaded here and the builds I used for testing are here. I'll paste the code for the test project below as well.
main.cpp
#include <QApplication> #include "Dialog.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Dialog dialog; return app.exec(); }Dialog.h
#ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include <QTextEdit> class Dialog : public QDialog { Q_OBJECT private: QTextEdit* dirContents; public: Dialog(); private slots: void OpenDir(); private: void ReadDir(QString path); }; #endif // DIALOG_HDialog.cpp
#include <QtWidgets> #include "Dialog.h" Dialog::Dialog() { dirContents = new QTextEdit(this); QPushButton* openDir = new QPushButton(tr("Open Directory"), this); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(dirContents); layout->addWidget(openDir); setLayout(layout); dirContents->setReadOnly(true); setWindowTitle(QString("Qt %1").arg(QT_VERSION_STR)); connect(openDir, SIGNAL(clicked()), this, SLOT(OpenDir())); show(); } void Dialog::OpenDir() { QFileDialog fileDlg(this); fileDlg.setFileMode(QFileDialog::Directory); fileDlg.setOptions(QFileDialog::ShowDirsOnly); fileDlg.setWindowTitle(tr("Open Directory")); fileDlg.setDirectory(QDir::homePath()); if (fileDlg.exec()) ReadDir(fileDlg.selectedFiles().at(0)); } void Dialog::ReadDir(QString path) { QDir dir(path); dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::LocaleAware); QFileInfoList fileList = dir.entryInfoList(); dirContents->clear(); dirContents->append(QString("%1\nNum Files: %2\n").arg(QDir::toNativeSeparators(path)).arg(fileList.size())); QFileInfoList::const_iterator file; for (file = fileList.constBegin() ; file != fileList.constEnd() ; ++file) dirContents->append(file->fileName()); }Can anyone suggest why files aren't showing up on the user's computer with Qt 5.10+? Is it something I'm doing wrong or is it likely a Qt problem?
-
Hi and welcome to devnet,
Does you user have that issue on all its disks or is it happening on for example a network drive ?
What filesystem is he using ?
Did he modify anything in his Windows machine settings ? -
He's working with files in his User directory on his main disk.
I'm not sure about his file system. It'll be either HFS+ or APFS but I'd have to check which.
He may have changed some settings, but it's hard to imagine any setting would result in a situation where Qt 5.9.0 builds works while Qt 5.10+ builds omit files.
He originally reported the problem over a year ago when he was using macOS 10.13 and he's still experiencing the same issue on 10.14. Programs built with Qt 5.9 work fine, but with Qt 5.10+ files with accents don't show up on his machine.