[Qt-interest] howto convert QString to char*
Carsten Breuer
CarstenBreuerQt at textwork.de
Tue Jul 13 23:47:40 CEST 2010
Hi Mathias,
> char * toChar(const QString str)
> {
> QByteArray ba = str.toLatin1();
> return ba.data();
> }
worse! da is destroyed when the function exits.
Are you sure that you doesn't have a constness problem?
What is the exact compiler error?
Try the following:
DllFunctionCall(qstring_inst.toAscii().data());
if the parameter is const.
Else:
QByteArray array = str.toAscii;
DllFunctionCall(array.data());
Regards,
Carsteb
>
> the bytearray contains usefull data,
> however the value returned by data() is very useless.
> Is this because ba is destroyed at the end of toChar?
> If so, what would you recommend to make such a conversion?
>
> In my code I use this to write
>
> QString sendSignal = "1.23 1" // this is set somewhere else
> char * str = toChar(sendSignal);
> ...
> // dll functions requiring a char* string...
>
> Matthias
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list