Ah, problem solved! On Tuesday 06 March 2007 01:00, Jim Bublitz wrote: > On Monday 05 March 2007 08:29, Paul Giannaros wrote: > > The documentation for KHTML's DOM::Document::getElementById ( > > http://api.kde.org/3.5-api/kdelibs-apidocs/khtml/html/classDOM_1_1Documen > >t. html#a20 ) show's that the method returns null when an element in the > > webpage by the given ID hasn't been found. I would have thought that > > would have mapped to Python's None, but instead I'm getting a > > khtml.DOM.Element. > > If the underlying C++ call returns null, the PyKDE call should return None > (see sip_api_return_from_new_instance in siplib/siplib.c) >
Aha, I see. > > Whenever I try to call a method on it, my application crashes with > > "terminate called after throwing an instance of 'DOM::DOMException'". > > Firstly, is this intended behaviour? > > I don't think so. > > > Secondly, is there any way that I can > > check if the return value from that call is a valid object? > > Try accessing some method of the object, I suppose (you can also check its > Python type, of course, but that only tells you what Python thinks the > object is). > > I'd suggest posting a short example program that demonstrates the problem > (include the html necessary to cause it too). > > Most of this stuff is straightforward sip wrappers - meaning sip generates > the code the same as for any other C++ class, and there isn't anything > unusual or customized that I can see. That suggests the most likely problem > is in the implementation you're doing - the commonest problem is not > keeping a Python reference to an object you're trying to access, for > example. > > However the khtml, and especially DOM, stuff hasn't gotten a lot of use, > and I have no application code to test it with, so problems either in PyKDE > or the underlying KDE code are quite possible too. > > Either way, an example would be useful to see what's happening. > > Jim It turns out that it was a documentation / cognitive problem. The docs say it returns null, but it turns out it just returns a 'null element'. You can call isNull() on the returned object to check whether or not it's valid. Thanks > > > Maybe there is > > something you can do with the sip module? (though I can't see anything in > > the docs) > > > > Thanks, > > Paul > > > > _______________________________________________ > > PyKDE mailing list [email protected] > > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde > > _______________________________________________ > PyKDE mailing list [email protected] > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde _______________________________________________ PyKDE mailing list [email protected] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
