È una buona idea usare QString::fromStdWString
ma (!!!) Se Qt è stato compilato con esattamente le stesse intestazioni STL del tuo progetto. In caso contrario, puoi divertirti molto, catturando un bug.
Se non sei sicuro che sia le intestazioni STL siano lo stesso utilizzo QString::fromWCharArray
:
std::wstring wideString;
QString qtString = QString::fromWCharArray( wideString.c_str() );
Aggiornare: Risposta a @juzzlin:
Immaginiamo che Qt sia stato costruito con lo stl contenente quanto segue std::wstring
:
class wstring { // I know, that there's no such class, but I'm shure you'll understand what I want to say
wchar_t * m_ptr;
size_t m_length;
...
};
E tu hai lo stl contenente quanto segue std::wstring
:
class wstring {
wchar_t * m_ptr;
wchar_t * m_the_end;
...
};
Se darà il tuo std::wstring
a qt, interpreterà m_the_end
puntatore come la lunghezza della stringa, e
Puoi divertirti molto, catturando un bug