[PyQt] QFileDialog error
Martin Airs
camberwell at gmail.com
Sat Jul 23 02:43:23 BST 2011
Good day all,
In this test case script I have added at the bottom, It bombs with this error...
[martin at 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_()
------------------------------------------------------
More information about the PyQt
mailing list