我和PySide有点问题。 我使用QtCore.QImage处理一些图像,但注意到路径名中没有打开包含unicode字符的图像文件。
于是我开始调查,发现q文件也发生了同样的问题。 在
尝试输入用testring编码的“utf8”和解码的unicode字符串。 两者的区别是一样的。
我也尝试了使用那些QFile.encodeName和QFile.decodeName函数,但是我所做的只是从文件名中删除非ascii字符。 在
我编写这个脚本是为了演示。 #! /usr/高兴的冰淇淋/env python
#-* -编码: utf-8-* -
导入操作系统
from PySide.QtCore import QFile,QIODevice
try:
操作系统. makedirs (u '/tmp/Qt测试' )。
except:
pass #probably dir just exists
操作系统. chdir (u '/tmp/Qt测试' ) )。
defmake_file(fn ) :
f=打开(fn,' w ' ) ) )。
f.close () )
defcheck_file(fn ) :
f=q文件(fn )
f.open(qiodevice.readonly ) )。
return f.is可重写(
fna=u'somefile.txt '
fnu=u'einhverskr.txt '
是make_file(FNA )
是make_file(FNU )
printf nau ' wasopenedsuccessfully 3360 ',check_file(FNA ) )。
printfnuu ' wasopenedsuccessfully 3360 ',check_file(FNU ) )。
print fna u' exists: ',OS.path.exists(FNA ) )。
打印fnu u ' exists : ',OS.path.exists(FNU ) )。
输出功率
^{pr2}$
有人给我说明吗? 在
更新
在查看源代码后,我注意到在unix上,QFile.open ) )总是使用此函数传递文件名。 staticqstringlocale _ decode (constqbytearrayf )。
{
# if定义(q _ OS _ Darwin ) )。
//macalwaysgivesusutf-8 and decomposed,we want that composed .
返回qstring :3360 from utf8(f ).normalized (qstring 33603360 normalization form _ c );
#ElifDefined(q_OS_Symbian ) ) ) ) ) ) ) )。
返回qstring :3360 from utf8(f;
#else
返回字符串:3360从本地8bit (f;
#endif
}
这通常会从字符串中删除unicode字符。 在