Reputation: 156
In this simple code I have trouble with Unicode:
QString qs = QFileDialog::getOpenFileName(0,"","","");
std::string str = qs.toUtf8().constData();
Mat m = imread(str);
When qs is Latin char set it works fine, but when path contains Cyrillic chars I obtain a bad conversion. As sample: qs "E:/Кирилиця_49.png": str "E:/Кирилиця_49.png"
I know that happens when str is not on UTF-8 characters set, but in project properties the "Character Set" property is "Use Unicode Character Set". Compiler MSVC 2010, Qt 5.3.2. What could be the problem?
Upvotes: 1
Views: 2306
Reputation: 42924
I believe QString::toUtf8()
is doing its job right (modulo some bug in Qt's implementation...).
The problem could be that you are using a debugger visualizer for the content of std::string
that is showing the string interpreting it using some "code page" instead of Unicode UTF-8.
Basically, the string content (as raw bytes) is correct (it's just the UTF-8 byte sequence corresponding to the original Unicode UTF-16 string): you are just using some "wrong-colored glasses" to look at it :)
The important point is: in what format does the imread()
function expect its string parameter to be? If imread()
expects an UTF-8 string, then you are right in passing a std::string
with UTF-8 encoded string to it as argument.
Upvotes: 1