[PyKDE] Problem resolving widget's class
Fredrik Juhlin
laz at strakt.com
Tue Nov 2 12:22:28 GMT 2004
On Monday 01 November 2004 19.30, David Boddie wrote:
> > Fredrik Juhlin wrote:
> > > From what we can tell though, it only happens to widgets that comes
> > > from "C++ land", so to speak. That is, widgets that are created by
> > > QWidgetFactory, the listbox you get when calling QComboBox.listBox(),
> > > the header from QListView.header() etc. This has made us draw the
> > > conclusion that there's most likely something wrong in SIP?
>
> This sounds a lot like the problems you can experience when embedding
> Python in C++ applications through a dlopened plugin mechanism.
> Can you successfully "cast" the widget pointers to the appropriate
> types by using sip.unwrapinstance and sip.wrapinstance functions?
First: We're not embedding Python in a C++ app. It's a pure Python
application.
Not knowing a whole lot about SIP, I looked through the SIP docs and added the
following lines of code at a known trouble spot (setting the text of QLabels
in forms), which I believe is what you meant I should try (if I got it wrong,
let me know :):
if not isinstance(labelWidget, qt.QLabel):
import sip
apa = sip.unwrapinstance(labelWidget)
foo = sip.wrapinstance(apa, qt.QLabel)
labelWidget = foo
I stuck this in before the setText() call. After a couple of attempts I
managed to provoke the error, but the result of the wrapinstance() call is
still a QWidget., not a QLabel.
//Fredrik
More information about the PyQt
mailing list