fix backport Qt5 issue

setCodecForCStrings not exist on Qt5, so we need use another
implementation for encoding on Qt4 instead.