Is there a difference between QFileDialog strings in PyQt4 and PyQt5?

The getOpenFileName function in PyQt4 returns a string that is the name of the selected file, and if none is selected then it returns an empty string.

filename = QFileDialog.getOpenFileName(self, "Open Template", "c:\\", "Templates (*.xml);;All Files (*.*)")

However in PyQt5 this returns a tuple of 2 elements where the first one is a string that has the same behavior as in PyQt4, and the second element is the filter used.

filename, filters = QFileDialog.getOpenFileName(self, "Open Template", "c:\\", "Templates (*.xml);;All Files (*.*)")

Note: The majority of documentation of PyQt5 is in Qt5, since in general the names of the methods, the inputs and the result are similar.

Leave a Comment