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编码