【小坑】之python2环境下QString转换至python的字符串

文章目录

1 问题

 当我使用python2环境的时候,因为对编码、解码的理解不是太好。所以,由pyqt4的文本框获得的文件夹地址是Qstring格式,导致转入自写函数槽的时候,会报错。
在这里插入图片描述

2 方法

QString转化string:
string = unicode(QString).encode(‘utf-8’)
如下示例代码:

from PyQt4 import QtCore
a = QtCore.QString('a')
print(a, type(a))
b = unicode(a).encode('utf-8')
print(b,type(b))
# 彩蛋
loc = loc.replace('\\', '/')  # 把文件地址的\变为/或者\\

具体可参考:
QString\string编码

猜你喜欢

转载自blog.csdn.net/qq_40260867/article/details/84106037