Phil Thompson <[EMAIL PROTECTED]> wrote: >> I understand the technical problem, but I believe it is a right >> expectation that any call to QScrollView.viewport() return a >> QWidget, as documented. The fact that thousands lines away I happen >> to have a QObject reference to the same object should not >> thoeretically make QScrollView.viewport() break its contract. > > Understood - but I'm concerned about possible unforeseen > implications. Of the two obvious options... > > 1) Re-type the existing object when the more specific type is known. > This is probably safe to do as far as the internals are concerned - > but the idea of a Python object changing type under your feet sounds > horrible. > > 2) Generate a new wrapper to the same C++ object with the more > specific type. This has obvious problems with ownership (who calls > the C++ dtor?), and things like "is" would fail. This is a real can > of worms.
I don't like either as well. The current logic, quoting you, is: > The most down-cast type, yes - but *only* if it is a know type. > Otherwise it resorts to the base type. Maybe this could be adjusted to: "automatically cast-down to the most derived type which is known". This way, calling parent() for QWidget's will always create at least a QWidget, since all widgets' parents are widgets themselves. Also, we would get a QWidget for the viewport too (which is derived from QWidget, in fact), and this would solve the problem. This is also what you say here, assuming I understood: > rather than see if the type *is* a known type, see if the type > is *derived* from a known type. Or maybe do the second only if the > first fails (for speed and to ensure it doesn't break existing > behaviour). so looks like we agree on this solution. >> Notice that there is *never* a need for downcast in PyQt, and this >> would be a sole example. > > Some PyKDE uses have this requirement - hence sip.cast(). I would like to see some. Giovanni Bajo _______________________________________________ PyKDE mailing list PyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde