2010年11月10日 星期三

Qt 字串轉換

//Convert a QString To LPCTSTR
LPCTSTR QString_To_LPCTSTR(QString mQTData)
{
    return (LPCTSTR)mQTData.utf16();
}

//Convert a QString To LPCSTR
LPCSTR QString_To_LPCSTR(QString mQTData)
{
    return (LPCSTR)mQTData.utf16();
}

//Convert a QString To LPTSTR
LPTSTR QString_To_LPTSTR(QString mQTData)
{
    return (LPTSTR)mQTData.utf16();
}

//Convert a LPCTSTR To QString
QString LPCTSTR_To_QString(LPCTSTR mWinData)
{
    return QString::fromUtf16((ushort*)mWinData);
}

//Convert a LPBYTE To QString
QString LPBYTE_To_QString(LPBYTE mWinData)
{
    return QString::fromUtf16((ushort*)mWinData);
}

//Convert a Char[] To QString
QString Char_To_QString(char mWinData[])
{
    return QString::fromUtf16((ushort*)mWinData);
}

//Convert a WCHAR* to a QString
QString WCHAR_to_QString(WCHAR* mBuffer)
{
    return QString::fromWCharArray(mBuffer);
}

//Convert a TCHAR To QString
QString TChar_To_QString(TCHAR mWinData[])
{
    return QString::fromUtf16((ushort*)mWinData);
}

資料來源 VQTConver

沒有留言: