PDA

View Full Version : QFileDialog question



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

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

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.

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

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

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

vuletic
14th March 2015, 12: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'], '')

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

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