Mars_Taxi
Mars_Taxi

Reputation: 61

UnicodeDecodeError when using QFileDialog getOpenFileName()

The code is like dlg = PyQt4.QtGui.QFileDialog(self) self.filename = dlg.getOpenFileName()

When the Dialog pops up, I click on a file having Chinese characters in its path. Then I get the UnicodeDecodeError.

I tried the toUtf8() function, but still get nowhere.

Unicode thing is always so difficult to understand. Anybody helps me out of this?

Upvotes: 2

Views: 1501

Answers (1)

pyos
pyos

Reputation: 151

The UnicodeDecodeError thing probably happens after the code you posted. Anyway, try

self.filename = PyQt4.QtGui.QFileDialog.getOpenFileName().decode('utf-8')

By the way, getOpenFilename() is a static method of QFileDialog, which means you don't have to create an instance to call it.

Upvotes: 1

Related Questions