[PyKDE] Type-errors and such...

Jesper Eskilson jojo at virtutech.se
Mon Dec 4 11:10:07 GMT 2000


I've used PyQt for a couple of months now, and most problems I've had with
PyQt boils down to one thing: type conversions.

- The error message "TypeError: Invalid argument types to..." is extremely
  annoying and almost completely useless since it gives no hint about (1)
  *what* argument is the culprit, (2) what type was expected, and (3) what
  type was actually found.

- I've found no documentation whatsoever about *how* PyQt (or sip?)
  converts C++ arguments to Python arguments. Yes, there is the PyQt
  documentation on what API calls differ substantially, but what I'm
  missing is some documentation guiding a new user as to how the
  Qt-documentations should be read when trying to figure out how to call a
  C++ method in Qt from Python. I encountered this problem when trying to
  create a QPointArray object. The PyQt-documentation said "fully
  implemented", and the C++ documentation said that the QPointArray
  constructor wanted a QPoint * as argument. Since there was no
  documentation on what this should be in Python, I guessed and passed a
  list of QPoint objects.

        list[0] = QPoint(0,0)
        list[1] = QPoint(1,0)

        array = QPointArray(list)        
  this did not work. All I got was the useless TypeError. I had to ask Phil
  about what to do, and he told me that the QPointArray constructor wants a
  list of integers: [x1,y1,x2,y2,x3,y3,...]. Quite an ok solution, but not
  very intuitive.

Take these two points together and things get worse. The TypeError
exception gives no hint at all, and the documentation only says "fully
implemented". I could live with the missing documentation if the exception
said "TypeError: first argument to QPointArray(): expected list of
integers, found list of QPoint". Or vice versa, if the documentation had
said that I needed a list of integers, I could live with the bad type-error

This problem is not much of a problem for experienced users, but it is a
major problem for newcomers, especially for those who know Qt, but want to
use it with a better language than C++. So, I think this is something worth
spending some time on. 

All in all, I think PyQt is an excellent piece of software.

Jesper Eskilson                                         jojo at virtutech.se
Virtutech                                         http://www.virtutech.se

More information about the PyQt mailing list