[PyQt] AttributeError: 'QString' object has no attribute 'endswith'

Yosbanis Vicente Gonzalez 90yobi90 at gmail.com
Tue Oct 25 17:37:00 BST 2016

Hello I'm new with PyQT and python. I am working an application with
directories. The problem is when I load a directory with QFileDialog:
(this the code)
        title = self.trUtf8('Seleccione el directorio de las imágenes a
        self.directory = QtGui.QFileDialog.getExistingDirectory(
            self, title)
        if self.directory:
            self.ledit_send_dir.setText(self.directory)  //QLineEdit()
            t = self.sizedir()  // in this function is the problem, this
function is for know the size of directory

(code of  function sizedir):
def sizedir(self):
        t = 0
        dir = self.ledit_send_dir.text()

        if path.isdir(dir):

            size_dir = 0

            for root, dirs, files in os.walk(dir):
                for name in files:
                    filename = join(root, name)
                    file_size = getsize(filename)
                    size_dir += file_size

            t = size_dir / pow(1024, 2)

        return t


This the description of the error:
Traceback (most recent call last):
  File "/home/imagis/PycharmProjects/reindexado/dcmregister.py", line 203,
in select_send_dir
    t = self.sizedir()
  File "/home/imagis/PycharmProjects/reindexado/dcmregister.py", line 221,
in sizedir
    for root, dirs, files in os.walk(dir):
  File "/usr/lib/python2.7/os.py", line 284, in walk
    if isdir(join(top, name)):
  File "/usr/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'QString' object has no attribute 'endswith'

I need help with this and I don't know how resolved.Please help men and
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161025/886c67e0/attachment.html>

More information about the PyQt mailing list