[PyKDE] Printing empty QStrings
Phil Thompson
phil at river-bank.demon.co.uk
Wed Nov 1 11:36:51 GMT 2000
Boudewijn Rempt wrote:
>
> On Mon, 30 Oct 2000, Phil Thompson wrote:
>
> >
> > It's the intended behaviour - but I'm not convinced it is the right
> > behaviour.
> >
>
> Well, let's try to find out which would be the more useful. The immediate
> problem is that if I create a dialog box with a number of entry fields
> (QLineEdits), I will have to check the result of text() with isEmpty(),
> since trying to print it will give an exception.
>
> I'm not entirely clear on this, since I have been writing far too much
> Java for my own good lately, but know I _can_ print Python None - perhaps
> it would be enough to return None for QString(), and trigger no exception?
>
> Thus:
>
>
> >>> print (QString())
> None
> >>> print (QString(""))
>
> >>> print (QString("a"))
> a
>
> instead of:
>
> >>> print (QString())
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.0/site-packages/qt.py", line 898, in
> __str__
> return str(self.sipThis)
> TypeError: __str__ returned non-string (type None)
This is sensible, but can't be achieved. It is Python raising the
exception (not PyQt) because PyQt is returning the None object instead
of a string object. PyQt could return a string object containing "None"
(although "null" would be better) but then 'print QString()' and 'print
QString("None")' would do exactly the same thing.
Phil
More information about the PyQt
mailing list