2016年12月20日 星期二

[Qt] JSON中Unicode / UTF8 轉換為QString方法

最近需要把JSON格式中的一些資料拿出來

看起來像是這樣:


....

"text": "\u4e00\u6bb5\u5149\u5f71,\u4e00\u6bb5\u65c5\u884c\uff0e\n\n   #\u4e58\u8457\u5149\u5f71\u53bb\u65c5\u884c\n #travel\n#light",

.....

(前後文就不特別放在這邊了,不重要)


那這種\u4e00\u6bb5... 取下來會是個QByteArray ,先把它們轉成QString

但還是一大串阿! 於是再用QString裡面的split  -> QStringlist來承接。

所以現在可以切開變成u4e00,但這還是一個UTF8,所以我們需要再做調整

上網找了很多方法都沒有找到,但是找到了一篇 這裡 於是終於找到方法了!



解決方法其實很簡單:


不管怎麼弄,反正把\u (escape) 這兩個字元弄掉(QString::replace / QString:: remove)

剩下4e00

    QString t1 = "4e00";
    int Hex = t1.toInt(0, 16);
    QString t2 = QChar(Hex);

你會發現t2 就轉成你要的字元了!

如此簡單就解決的困難的問題,就是這樣(我有簡化掉那篇的方法)

End

2016年8月17日 星期三

[VC++] Visual Studio 2005 搭配win7 相容性錯誤的解決方法

已知VS2005安裝在win7會有相容性問題,該怎麼解決網路上也有各種說法

但最後解決的辦法是看到stackoverflow上面的這篇文章:

http://stackoverflow.com/questions/1901492/windows-7-visual-studio-2005-compatibility




I had a similar problem when I was installing Visual Studio 2005 Professional on a Windows 7 machine. But here is what I did to fix the problem:
  1. Install Visual Studio 2005 Professional During the install, a window popped up saying that VS2005 might not be compatible with Windows 7. Ignore this warning and continue.
  2. Install Microsoft® Visual Studio® 2005 Team Suite Service Pack 1 VS80sp1-KB926601-X86-ENU.exe Link: Microsoft® Visual Studio® 2005 Team Suite Service Pack 1
  3. Install Visual Studio 2005 Service Pack 1 Update for Windows Vista VS80sp1-KB932232-X86-ENU.exe Link: Visual Studio 2005 Service Pack 1 Update for Windows Vista
Note: If you try and install #3 before #2, you will end up with a message that says : "The upgrade patch cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade patch."
Hope it helps.


看看這邊的回應,他是說先安裝VS2005 然後安裝team suite 最後才安裝SP1 update(順序不要搞混)

不然會出現已經安裝新版本之類的錯誤訊息


附上兩個連結 ,就這樣! end

2016年5月3日 星期二

[C++] WIA with VC++ 無法解析的外部符號 / 解決方法

在寫WIA的時候遇到了一個很棘手的問題,

大概錯誤訊息如:

error LNK2001: unresolved external symbol _CLSID_WiaDevMgr
error LNK2001: unresolved external symbol _IID_IWiaDevMgr

找了三天還是沒結果,後來才了解,解法:



就是這樣,在Project裡面的連結器(Linker)-->輸入(input)-->其它相依性輸入"WiaGuid.Lib"

問題解決! (記錄起來以免忘記)


END

2016年4月26日 星期二

[C++] Messagebox with int/long value , or text 如何顯示?

Debug時候,有時需要使用Messagebox,

但是要加入特定文字,或是變數該怎麼讓他顯示呢?

先從文字開始:

MessageBox(HWND hwnd, LPCWSTR lpText,LPCWSTR lpCation , UINT uType);

hwnd因為不需要特別設定 = 0

LPCWSTR  lpText是Box內想說的話 --->    _T("我想說的話")

LPCWSTR  lpCation是Box的標題 --->    _T("我的標題")

UINT uType 就是可以讓他選OK cancel等按鈕,這邊是填入MB_OK(可以自行調整)





我要填入ulong / int  怎麼辦??

CString msg;
msg.Format(_T("%d").變數名稱);
AfxMessageBox(msg);


這樣就可以囉!


END






2016年4月22日 星期五

[C++] Visual Studio 遇到ATL Com Crash的問題(解決方案)

在做IMAPI的東西的時候,需要用到CoCOM的東西,

然後他又需要使用ATL....總之很麻煩0rz


好了,重點就是在trace bug的時候跑到atlcom.h這個檔案裡面的

class CComObjectCached : public Base
{
public:
typedef Base _BaseClass;
CComObjectCached(void* = NULL){}
// Set refcount to -(LONG_MAX/2) to protect destruction and
// also catch mismatched Release in debug builds
// This will be made virtual again for Beta 2
/*virtual*/ ~CComObjectCached()
{
m_dwRef = -(LONG_MAX/2);
FinalRelease();
#ifdef _ATL_DEBUG_INTERFACES
_AtlDebugInterfacesModule.DeleteNonAddRefThunk(_GetRawUnknown());
#endif
}
//If InternalAddRef or InternalRelease is undefined then your class
//doesn't derive from CComObjectRoot
STDMETHOD_(ULONG, AddRef)() throw()
{
ULONG l = InternalAddRef();
if (l == 2)
_pAtlModule->Lock();
return l;
}

沒錯,就是_pAtlModule->Lock();這邊,然後你發現他記憶體位址居然是0x000000

然後就crash了!


不要相信甚麼add ATL support to MFC 之類的鬼話(加了以後我不知道怎麼刪掉,只能重寫)

解決方法:

在你的主程式(.cpp)裡面,

#include .......

//在這邊新增
CComModule _Module;
extern __declspec(selectany) CAtlModule* _pAtlModule=&_Module;

//新增完成

主程式:建構子....

主程式.....

這樣就可以解決了

END

2016年3月9日 星期三

[C++] Visual C++ 2005 遇到的問題- fatal error LNK 1103 解決方法

遇到這個問題,網路上也是有很多解法,

其實不外乎就是VC 2005有bug ,所以需要補釘(hotfix)

但是問題是hotfix在microsoft官網已經掛點了

所以你需要

https://mega.nz/#!V5VhgDyR!F4MKmJzRFi0_vVLofU7qYImIjSy42AXVOPh09DVDisQ

這個補釘

如果還是不夠還需要另一個"VS80sp1-KB926603-X86-CHT"這個檔案,但這個檔案網路上可以找到,就不提供了

END