[Qt-interest] QString to TCHAR* and back

Duane Hebert spoo at flarn.com
Wed Feb 24 18:55:57 CET 2010


>Try this code, it's work fine for my problem.

>QString to TCHAR
>    TCHAR buffer[ MAX_PATH ];
>    filepath.toWCharArray( buffer );
>    buffer[ filepath.length() ] = '\0';

I had to create a function to do this so I did it like this:

int QStringToTCharBuffer(QString buffer, TCHAR* Array){
    return buffer.toWCharArray(Array);
}

The bad part is that the caller has to create the TCHAR* large enough
to hold the QString, and set the terminator.

I guess, the other option would be to return a std::wstring and have the caller do .c_str().

The other way around is fine because we can return a QString.  



More information about the Qt-interest-old mailing list