I am using QT V6.1.1 on windows 10. I noticed that QDir will not find file with a single quote in a filter, even though windows allows this. Is there a list of illegal characters qt doesn't allow in path names?
Thanks
Printable View
I am using QT V6.1.1 on windows 10. I noticed that QDir will not find file with a single quote in a filter, even though windows allows this. Is there a list of illegal characters qt doesn't allow in path names?
Thanks
Qt just uses the OS directory iteration APIs. Are you saying that something like this:
does not list a file containing a single quote in its file name. Certainly does here on Linux:Code:
#include <QCoreApplication> #include <QDir> #include <iostream> int main(int argc, char** argv) { QFileInfoList list = dir.entryInfoList(); std::cout << " Bytes Filename" << std::endl; for (int i = 0; i < list.size(); ++i) { .arg(fileInfo.fileName())); std::cout << std::endl; } return 0; }
Code:
13:38:09: Starting /tmp/tt/build-a-Desktop_Qt_6_1_1_GCC_64bit-Debug/a ... Bytes Filename 0 file_with_'quote 36 a.pro 671 main.cpp 34117 a.pro.user 13:38:09: /tmp/tt/build-a-Desktop_Qt_6_1_1_GCC_64bit-Debug/a exited with code 0
Thanks for the reply. I'm using windows 10, not LINUX. Here is the exact code I'm using:
Code:
QStringList filters; filters << info.completeBaseName()+QStringLiteral("*.*"); dir.setNameFilters(filters);
When this code is run with a file name that contains a ', the files list is empty. It works as expected when the ' is removed from the file name.
The completebasename contains a ;, so what I searching for is: abs'xyz*.*
This works perfectly fine for me:
Code:
dir.setNameFilters({ QStringLiteral("*'*.*") }); for (const QString& file : files) qDebug() << file;
-> output:
"bl'b.txt"
I guess I need to dig deeper. I created a file in a folder with a single quote and a file name with a single quote and it worked fine. When it failed before I removed the single quotes and the problem went away, so I concluded that it was the single quote that caused the problem. I'm very sorry to have wasted your time.
No harm, no foul. It is precisely these little oddities that often escape testing. There was always the possibility that the character you thought was a simple apostrophe was in fact a "smart" quote or that there were non-printables embedded in the file name causing something to break the Windows file globbing.