[PyKDE] Printing empty QStrings

Phil Thompson phil at river-bank.demon.co.uk
Thu Nov 2 18:50:27 GMT 2000


Pete Ware wrote:
> 
> I had to do a bunch of work to go from python 1.5.2 to python 1.6 &
> PyQt 2.0 because of the string changes.  I have a lot of code
> fragments that look like:
> 
>         # From a qt.QLineEdit object
>         text = self.comment.text ()
>         if text.length() == 0:
>                 text = ''
>         else:
>                 text = str (text)
> 
> and
> 
>         # From a file dialog
>         filename = qt.QFileDialog.getSaveFileName (init, '',
>                         self.parent, 'Save the .submit as')
>         if filename.isNull():
>                 return
>         filename = str (filename)
> 
> I doubt there is one best answer so sticking with something is
> probably the solution.

I'm more and more inclined to go with repr of a null QString and an
empty QString to both return an empty Python string. Generally QString
methods are "safe" for null strings and I think this should be too. This
shouldn't break anything like the code above (just makes some of if
redundant).

Unless anyone has any violent objections I'll make this (last) change in
2.2.

Boudewijn - I'll change the documentation you sent me accordingly.

Phil




More information about the PyQt mailing list