View Full Version : QFileDialog question

13th March 2015, 21:34
Hello, I have small problem using QFileDialog, for example:

filename = QtWidgets.QFileDialog.getOpenFileName(self,"Open File")

and lets say I open Tekst.txt file, I get this printed:

('/home/whatever/Tekst.txt', '')

but I would like to get only this '/home/whatever/Tekst.txt', I know I can fix it by removing ( ,") manually but I would like to avoid that.

13th March 2015, 23:15
No idea where you get that from. getOpenFileName() returns a single string, not a list.

14th March 2015, 00:03
Yeah that's what I was expecting but, I guess il need to use filename= filename[0] to get what I need, thanks.

14th March 2015, 02:12
Are you sure you're not using QFileDialog::getOpenFileNames() - notice the plural, which does return a QStringList...

14th March 2015, 11:24
Yeah I'm using getOpenFileName(), but I tried getOpenFileNames() aswell just to see what I'll get, it was this :

(['/home/whatever/Tekst.txt'], '')

14th March 2015, 17:03
Could be a bug in PyQt I guess... The return from getOpenFileName is a QString, not a QStringList.

14th March 2015, 23:51
I don't think it is a bug. I'd suspect the second entry from the tuple returns the selected filter.