<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-9"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Le 23/07/11 07:07, Yaşar Arabacı a écrit :
    <blockquote
cite="mid:CAFEUn8Yf4UkrAex-_RLNh8nLYXc=eLDN-c0GtVQGK7Dv3sAuHQ@mail.gmail.com"
      type="cite"><br>
      <br>
      <div class="gmail_quote">---------- Yönlendirilmiş ileti
        ----------<br>
        Kimden: <b class="gmail_sendername">Yaşar Arabacı</b> <span
          dir="ltr"><<a moz-do-not-send="true"
            href="mailto:yasar11732@gmail.com">yasar11732@gmail.com</a>></span><br>
        Tarih: 23 Temmuz 2011 08:07<br>
        Konu: Re: [PyQt] QFileDialog error<br>
        Kime: Martin Airs <<a moz-do-not-send="true"
          href="mailto:camberwell@gmail.com">camberwell@gmail.com</a>><br>
        <br>
        <br>
        What happens when you assign it to its own string. Do you get
        error while assigning it to string or when using that string
        with file dialog?
        <div>
          <div class="h5"><br>
            <br>
            <div class="gmail_quote">2011/7/23 Martin Airs <span
                dir="ltr"><<a moz-do-not-send="true"
                  href="mailto:camberwell@gmail.com" target="_blank">camberwell@gmail.com</a>></span><br>
              <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
                0.8ex; border-left: 1px solid rgb(204, 204, 204);
                padding-left: 1ex;">Good day all,<br>
                <br>
                In this test case script I have added at the bottom, It
                bombs with this error...<br>
                <br>
                [martin@desktop python]$ python testcase.py<br>
                Traceback (most recent call last):<br>
                 File "testcase.py", line 17, in pressed<br>
                   filename = QtGui.QFileDialog.getOpenFileName(self,
                'Open file', os.path.split(self.lineedit.text())[0],
                "logs")<br>
                 File "/usr/lib64/python2.7/posixpath.py", line 83, in
                split<br>
                   i = p.rfind('/') + 1<br>
                AttributeError: 'QString' object has no attribute
                'rfind'<br>
                <br>
                <br>
                I cant quite work out why, if I take the
                *os.path.split(self.lineedit.text())* out and put it on
                a seperate line assigning it to its own<br>
                string it still doesn't work<br>
                <br>
                I wonder if anyone could show me how to get round this,
                please<br>
                <br>
                Thanks in advance<br>
                <br>
                Martin Airs<br>
                <br>
                ------------------------------------------------------<br>
                import sys, os<br>
                from PyQt4 import QtCore, QtGui<br>
                <br>
                class Window(QtGui.QWidget):<br>
                   def __init__(self, parent=None):<br>
                       QtGui.QMainWindow.__init__(self, parent)<br>
                       self.hbox = QtGui.QHBoxLayout()<br>
                       self.lineedit = QtGui.QLineEdit("", self)<br>
                       self.lineedit.setText("/var/log/test.log")<br>
                       self.button = QtGui.QPushButton("open file",
                self)<br>
                       self.hbox.addWidget(self.lineedit)<br>
                       self.hbox.addWidget(self.button)<br>
                       self.setLayout(self.hbox)<br>
                       self.button.clicked.connect(self.pressed)<br>
                <br>
                   def pressed(self):<br>
                       filename =
                QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                os.path.split(self.lineedit.text())[0], "logs")<br>
                <br>
                app = QtGui.QApplication(sys.argv)<br>
                window = Window()<br>
                window.show()<br>
                app.exec_()<br>
                ------------------------------------------------------<br>
                _______________________________________________<br>
                PyQt mailing list    <a moz-do-not-send="true"
                  href="mailto:PyQt@riverbankcomputing.com"
                  target="_blank">PyQt@riverbankcomputing.com</a><br>
                <a moz-do-not-send="true"
                  href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt"
                  target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
              </blockquote>
            </div>
            <br>
          </div>
        </div>
      </div>
      <br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
PyQt mailing list    <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></pre>
    </blockquote>
    It's normal,  lineedit.text() returns a QString and Python don't
    like that.<br>
    <br>
    Use :  os.path.split(str(self.lineedit.text()))<br>
    <br>
    <div class="moz-signature">-- <br>
      Vincent V.V.<br>
      <a href="https://launchpad.net/oqapy">Oqapy</a> . <a
        href="https://launchpad.net/qarte+7">Qarte+7</a> . <a
        href="https://launchpad.net/paqager">PaQager</a></div>
  </body>
</html>