How to convert LPTSTR to QString or QByteArray



  • Hi All

    I am storing some value in LPTSTR which now i want to send to my AT application.
    So can anyone tell me how to convert this to QString or QByteArray.

    BR
    Rajveer



  • try:
    @LPTSTR myStr;
    ...
    QString convertedStr = QString::fromLocal8Bit((const char *)myStr);@



  • if you use Unicode charset LPTSTR will be typedef of LPWSTR, in this case use
    @QString QString::fromWCharArray ( const wchar_t * string, int size = -1 )@



  • Hi

    If i do as shown below I am receiving only one character in QString.
    QString convertedStr = QString::fromLocal8Bit((const char *)myStr);

    How to get the full data.



  • As "AcerExtensa" I think you use unicode character set (in latest VC versions this is the default)
    So you could try something like this:
    @
    #ifdef UNICODE
    QString convertedStr = QString::fromWCharArray(yourLPTSTR)
    #else
    QString convertedStr = QString::fromLocal8Bit(yourLPTSTR)
    #endif
    @



  • [quote author="cincirin" date="1326884757"]As "AcerExtensa" I think you use unicode character set (in latest VC versions this is the default)
    So you could try something like this:
    @
    #ifdef UNICODE
    QString convertedStr = QString::fromWCharArray(yourLPTSTR)
    #else
    QString convertedStr = QString::fromLocal8Bit(yourLPTSTR)
    #endif
    @[/quote]

    and set second param - datasize for your string


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.