Unsolved QString corruption
-
Our app relies on ICU library for internationalization. Up till now, we had a static global variable which would call the function with following line
Locale::setDefault(Locale(lname), error_code);
to create and initialize the ICU library there by initializing our internationalization library.
However, with the upgrade of compilers, we are running into static initialization fiasco.
So we removed that variable and we are making our components to explicitly call the initialization function to boot the i18n library.After doing that, we are finding that some of our components (which depend and links against QTCore lib) which uses QString are receiving corrupted characters.
We internally use char16_t for our cross platform wide character type data and the operation that's failing is as belowQString toQString( const std::u16string& str ) { return QString(reinterpret_cast<const QChar *>(str.data()), (int)str.size()); }
This is creating a corrupted QString and we are failing understand as to why this might be happening.
- Is there any connection here between initializing the ICU locale library in static global variable (done at very early stages of app loading) and QString class being good while in other case its behaving badly ?
- Does QT uses ICU which is initialized in similar fashion using global static variable ?
-
reinterpret_cast<const QChar *>(str.data())
this won't/can't ever work
std::u16string cannot be cast to an "arbitrary" class.untested:
QString::fromUtf16( str.data() );
-
This post is deleted!