[Qt-interest] How to convert a LPCTSTR into a QString

Jason H scorp1us at yahoo.com
Wed Jun 16 23:36:18 CEST 2010


I don't know that fromLocal8Bit() would work, particularly if you have UNICODE defined.
QString should be WCHAR (Unicode, UTF-16)
QByteArray should be CHAR (ASCII, UTF-8)

TCHAR is one of the two. I'd mirror the #ifdef,  if you can't nail your platform down.

The best bet is using fromWCharArray()




----- Original Message ----
From: Matthias Pospiech <matthias.pospiech at gmx.de>
To: qt-interest at trolltech.com
Sent: Wed, June 16, 2010 5:18:30 PM
Subject: [Qt-interest] How to convert a LPCTSTR into a QString

I have a Windows Message call containing a LPCTSTR, which is defined as

#ifdef UNICODE
    typedef WCHAR TCHAR;
#else
    typedef CHAR TCHAR;
#endif
typedef const TCHAR *LPCTSTR;

If I now try to convert using:

void Controller::Error(LPCTSTR errorMessage)
{
    emit errorOccurred(QString::fromLocal8Bit(errorMessage));
}

I get the error:
error: no matching function for call to 'QString::fromLocal8Bit(const 
TCHAR*&)'

what should the solution look like?

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