Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.5.1
-
None
-
OSX 10.10.5 Qt 5.5.1 from git
Description
- Create a directory containing the ä character and run the program below:
#include <QCoreApplication> #include <QFileSystemWatcher> #include <QDebug> #include <QFile> namespace { const auto dir = "/YOUR_PATH/Täst"; class Watcher : public QFileSystemWatcher { public: Watcher() { connect(this, &QFileSystemWatcher::directoryChanged, this, [](const QString& dir) { qDebug()<<"dir changed:"<<dir; }); } }; }//< ns int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Watcher w; qDebug()<<"add path success?"<<w.addPath(dir); return a.exec(); }
- Add/remove files into/from the created folder
- You will not see "dir changed:" printed on modification
Reason
The folder path is added to the watcher's internal hash with one encoding (using QString::fromLocal8Bit), but when a change occurs, the folder to query is with different encoding (using QFile::decodeName), thus the hash fails to find a match as if the folder is not monitored at all.
Workaround
None! Even if someone adds a string with an explicit QFile::decodeName encoding, the string is always first "converted" by a QString::fromLocal8Bit call.
Solution
The path added must be with the exact same encoding as the one that is queried later.
We must either fixup QFseventsFileSystemWatcherEngine::addPaths to explicitly store a QFile::decodeName path
or
Fix FileSystemEngine::canonicalName (used by QFileInfo::canonicalFilePath, used by QFseventsFileSystemWatcherEngine::addPaths) to use QFile::decodeName instead QString::fromLocal8Bit:
/qt5/qtbase/src/corelib/io/qfilesystemengine_unix.cpp
QFileSystemEngine::canonicalName
line: 289:
QString canonicalPath = QDir::cleanPath(/*QString::fromLocal8Bit*/QFile::decodeName(ret));
This works
Question: What is the difference b/w QString::fromLocal8Bit and QFile::decodeName? To what extend are interchangeable?
Attachments
Issue Links
- relates to
-
QTBUG-55896 QFileSystemWatcher can't watch paths with some Unicode characters on macOS
-
- Closed
-