{"id":128,"date":"2015-05-10T23:46:34","date_gmt":"2015-05-11T07:46:34","guid":{"rendered":"https:\/\/www.actinia.me\/?p=128"},"modified":"2016-04-10T17:54:54","modified_gmt":"2016-04-11T01:54:54","slug":"chinese-character-coding-problem-in-pyqt4","status":"publish","type":"post","link":"https:\/\/www.actinia.me\/?p=128","title":{"rendered":"Chinese character coding problem in pyqt4"},"content":{"rendered":"<p>I want to save a file with a Chinese name in pyqt.<\/p>\n<p><strong>It reports<\/strong>: <code>IOError: [Errno 22] invalid mode ('w') or filename: PyQt4.QtCore.QString(u'D:\/Users\/zhout_000\/Desktop\/\\u672a\\u547d\\u540d.dxf')<\/code><\/p>\n<p><strong>Reason<\/strong>: the type of the filename read from the file dialog is infact &#8220;QString&#8221;,\u00a0not&#8221;string&#8221;<\/p>\n<p><strong>Solve<\/strong>: convert QString to unicode\uff1a\u00a0<code>fileName=unicode(QtCore.QString(fileName))<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to save a file with a Chinese name in pyqt. It reports: IOError: [Errno 22] invalid mode (&#8216;w&#8217;) or filename: PyQt4.QtCore.QString(u&#8217;D:\/Users\/zhout_000\/Desktop\/\\u672a\\u547d\\u540d.dxf&#8217;) Reason: the type of the filename read from the file dialog is infact &#8220;QString&#8221;,\u00a0not&#8221;string&#8221; Solve: convert QString to unicode\uff1a\u00a0fileName=unicode(QtCore.QString(fileName))<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/128"}],"collection":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=128"}],"version-history":[{"count":2,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions\/135"}],"wp:attachment":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}