[Qt-interest] howto convert QString to char*

Matthias Pospiech matthias.pospiech at gmx.de
Tue Jul 13 17:45:57 CEST 2010


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.
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



More information about the Qt-interest-old mailing list