jeudi 22 janvier 2015

How to convert QString in Qt5 to LPCSTR in Visual Studio 2013

I found this (useless in my case) question: How to convert QString to LPCSTR (Unicode) which most of you probably would consider duplicate, but I think it's either related to different Qt / VS / C++ version or just has no correct answers (despite some is marked so).


I have this code using Qt5 in Visual Studio 2013 on Windows 7, using C++11 standards, it uses all of the proposed solutions in linked answer:



QString test = "hello world";
// 1
LPCSTR lp1 = _T(test.toLocal8Bit().constData());
// 2
LPCSTR lp2 = _T(test.toUtf8().toStdString().c_str());
// 3
LPCSTR lp3 = _T(test.toLatin1().toStdString().c_str());




  1. Produces


    îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþç'Û)ÆS2¹ú¨ºú




  2. Produces


    îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþFþš




  3. Produces


    îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþFþš




How do I convert it?


Aucun commentaire:

Enregistrer un commentaire