Qt 常用类型转换

2020-05-15  本文已影响0人  爱写诗的程序员zxp

QString 转 BSTR

1、BSTR s = SysAllocString(L"s1");
2、QString s2 = "test string";
      BSTR s = SysAllocString((OLECHAR*)s2.unicode());

BSTR 转 QString

BSTR bstr;
QString s = QString::fromUtf16(reinterpret_cast<ushort*>(bstr));

LPCWSTR 转 QString

LPCWSTR lpszStr;
QString s1 = QString::fromStdWString(lpszStr);

QString 转 LPCWSTR

QString s1 = "test string";
std::wstring wlpstr = s1.toStdWString();
LPCWSTR lpcwStr = wlpstr.c_str();

QString 地址串 转 16进制值

QString src = "0xba451641";
QString s = src .mid(src .indexOf("x") + 1);
LONGLONG ll = s.toUtf8().toUInt(Q_NULLPTR, 16);

LPCTSTR转QString

LPCTSTR lpctStr;
QString s = QString::fromUtf16(reinterpret_cast<ushort*>((LPTSTR)lpctStr));
上一篇 下一篇

猜你喜欢

热点阅读