Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PySide: QFileDialog.getOpenFileName returns string of tuple instead of just string
Forum Updated to NodeBB v4.3 + New Features

PySide: QFileDialog.getOpenFileName returns string of tuple instead of just string

Scheduled Pinned Locked Moved Language Bindings
7 Posts 4 Posters 13.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andylomas
    wrote on 3 Sept 2010, 19:12 last edited by
    #1

    I just posted this to the Qt General forum on Forum.Nokia, but I think this might be a more appropriate forum for PySide questions...

    I'm trying to convert an application from PyQt4 to Qt and have found what appears to be a difference in the return results from QFileDialog.getOpenFileName

    I'm calling QFileDialog with the following call:

    filepath = unicode(QFileDialog.getOpenFileName(self, "Species Explorer - Open Species", dir, "Species Files (*.species)"))

    When I use PyQt4 I just get a string with the file selected using the dialog box. For example:

    C:/production/species/testSpecies.species

    When I use PySide I get a string that contains a tuple with two sub-strings: the filename and the value of the filter. For instance:

    (u'C:/production/species/testSpecies.species', u'Species Files (*.species)')

    Is this the expected behaviour?

    I'm using PySide for Windows, pyside-0.4.0-py2.6

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danilocesar
      wrote on 3 Sept 2010, 21:46 last edited by
      #2

      <a href="http://www.pyside.org/docs/pyside-dev/PySide/QtGui/QFileDialog.html#PySide.QtGui.QFileDialog.getOpenFileName">Documentation</a> shows it should return a string

      File a bug: "http://bugs.openbossa.org":http://bugs.openbossa.org

      [edit: text to link / $chetankjain ]

      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
      Software Engineer

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andylomas
        wrote on 4 Sept 2010, 16:54 last edited by
        #3

        Thanks for the link to the bug reporting site. I've filed a report.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on 6 Sept 2010, 06:46 last edited by
          #4

          They're returning the selected filter as well, which fits the behavior of QFileDialog::getOpenFileName(). You might not be aware of it, but the C++ implementation has a QString pointer argument that you can use to get the selected filter. Python doesn't have such a system (not explicitly at least) and you get a tuple containing the file and the filter. getOpenFileNames would (and should) probably return a tuple of a QStringList and a string.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andylomas
            wrote on 6 Sept 2010, 12:54 last edited by
            #5

            I guess it makes sense having a mechanism to get hold of the selected filter, but it does mean that it has broken API compatibility with PyQt which just returns a string with the filename.

            One idea, I guess, would be to have an additional optional parameter to the Python call, say selectedFilter=True, that if you set then you get the tuple with the selected filter in the result. That would at least keep consistency with PyQt and allow the user to get hold of which filter was used if they want to.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Franzk
              wrote on 7 Sept 2010, 12:10 last edited by
              #6

              Since type checking is a big nono in Python, the API functions preferably return one and only one type of argument. It makes sense then to do what PyQt has already done: a function QFileDialog.getOpenFileNameAndFilter().

              Other than that I wasn't aware of the fact that PySide is trying to stay interface compatible with PyQt. I for one couldn't really care about it as long as it stays consistent with the C++ implementation. I can imagine other people will, though.

              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hugopl
                wrote on 10 Sept 2010, 22:50 last edited by
                #7

                It remains compatible with PyQt, but with PyQt API2, not API1.

                If you use PyQt with API2 you will get the same behaviour because there's no QString and python string and unicode objects are immutable.

                1 Reply Last reply
                0

                1/7

                3 Sept 2010, 19:12

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved