Results 1 to 7 of 7

Thread: QFileDialog question

  1. #1
    Join Date
    Dec 2014
    Posts
    29
    Thanks
    12
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default QFileDialog question

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileDialog question

    No idea where you get that from. getOpenFileName() returns a single string, not a list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    vuletic (14th March 2015)

  4. #3
    Join Date
    Dec 2014
    Posts
    29
    Thanks
    12
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog question

    Yeah that's what I was expecting but, I guess il need to use filename= filename[0] to get what I need, thanks.

  5. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFileDialog question

    Are you sure you're not using QFileDialog::getOpenFileNames() - notice the plural, which does return a QStringList...

  6. #5
    Join Date
    Dec 2014
    Posts
    29
    Thanks
    12
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog question

    Yeah I'm using getOpenFileName(), but I tried getOpenFileNames() aswell just to see what I'll get, it was this :

    (['/home/whatever/Tekst.txt'], '')
    Last edited by vuletic; 14th March 2015 at 11:40.

  7. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QFileDialog question

    Could be a bug in PyQt I guess... The return from getOpenFileName is a QString, not a QStringList.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileDialog question

    I don't think it is a bug. I'd suspect the second entry from the tuple returns the selected filter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 7
    Last Post: 5th March 2014, 17:36
  2. QFileDialog Question
    By sgrant327 in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2010, 14:05
  3. Replies: 0
    Last Post: 31st March 2010, 12:40
  4. QFileDialog
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2007, 13:41
  5. A question about QFileDialog::getSaveFileName
    By Ali in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 19:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.