View Full Version : How to convert wchar_t* into char*??

22nd June 2006, 10:34

I want to convert wchar_t* into char*. Can anybody tell me how to achieve this without information loss??

Thanks in advance.


22nd June 2006, 11:19
I think you'd have to convert it to std::wstring and then use QString::fromStdWString() to convert to a QString and then you can convert it using QString::unicode() or using qPrintable() (be ready for a data loss in this situation, as your local encoding may not support all unicode characters).

22nd June 2006, 11:32
Thanks wysota,

But again QString.unicode will give me const QChar*. QChar is of 2 bytesin Qt. I want pure char* as i want to write it into file in UTF16 encoding.

Actually i have QString. I want to convert it in UTF16 using QString.utf16() and then I want to write it into file. But as u know QFile does not allow us to write unicode directly. So first we have to convert it into char* and then we can write it to file.

Can u give me suggestions for this??

Again thanksin advance.


22nd June 2006, 13:39
Then use QTextCodec.