[Qt-interest] howto convert QString to char*

Gabriel M. Beddingfield gabrbedd at gmail.com
Tue Jul 13 20:02:26 CEST 2010



On Tue, 13 Jul 2010, Matthias Pospiech wrote:

>>> I am using the following:
>>>
>>>     char * toChar(const QString str)
>>>     {
>>>         QByteArray ba = str.toLatin1();
>>>         return  ba.data();
>>>     }
>>>
>>> the bytearray contains usefull data,
>>> however the value returned by data() is very useless.

I was curious, so I set up a simple test here.  With Qt 
4.5.3, your toChar() works fine... as does the two that I 
proposed.

Maybe there's something else going on... like the original 
string changing unexpectedly?

-gabriel



More information about the Qt-interest-old mailing list