Le 23/07/11 07:07, Yaşar Arabacı a écrit :
---------- Yönlendirilmiş ileti
----------
Kimden: Yaşar Arabacı <yasar11...@gmail.com>
Tarih: 23 Temmuz 2011 08:07
Konu: Re: [PyQt] QFileDialog error
Kime: Martin Airs < camberw...@gmail.com>
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?
2011/7/23 Martin Airs <camberw...@gmail.com>
Good day all,
In this test case script I have added at the bottom, It
bombs with this error...
[martin@desktop python]$ python testcase.py
Traceback (most recent call last):
File "testcase.py", line 17, in pressed
filename = QtGui.QFileDialog.getOpenFileName(self,
'Open file', os.path.split(self.lineedit.text())[0],
"logs")
File "/usr/lib64/python2.7/posixpath.py", line 83, in
split
i = p.rfind('/') + 1
AttributeError: 'QString' object has no attribute
'rfind'
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
string it still doesn't work
I wonder if anyone could show me how to get round this,
please
Thanks in advance
Martin Airs
------------------------------------------------------
import sys, os
from PyQt4 import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.hbox = QtGui.QHBoxLayout()
self.lineedit = QtGui.QLineEdit("", self)
self.lineedit.setText("/var/log/test.log")
self.button = QtGui.QPushButton("open file",
self)
self.hbox.addWidget(self.lineedit)
self.hbox.addWidget(self.button)
self.setLayout(self.hbox)
self.button.clicked.connect(self.pressed)
def pressed(self):
filename =
QtGui.QFileDialog.getOpenFileName(self, 'Open file',
os.path.split(self.lineedit.text())[0], "logs")
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
app.exec_()
------------------------------------------------------
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
It's normal, lineedit.text() returns a QString and Python don't
like that.
Use : os.path.split(str(self.lineedit.text()))
|
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt