[PyKDE] RE: QDict support in PyQT

Jim Bublitz jbublitz at nwinternet.com
Tue Oct 30 15:53:20 GMT 2001


On 30-Oct-01 ian reinhart geiser <geiseri at yahoo.com> wrote:

> I have a situation where I have a set of QDicts that I would
> like to have available to my Python bindings from SIP.  I
> noticed this was absent from the bindings.

Yes - sip doesn't support template classes automatically (or
generally) yet. It's necessary to handwrite code for each unique
instance of a template class.

> Can any one give me advice on how to make these
> dictionary objects available to my python code.  AFAIK the
> python dictionaries are very much like the QT ones.

You need to create a %MappedType somewhere in your sip files, or
in a separate sip file for each instance (for example, one for
QDict<char>, one for QDict<KSomeClass>, etc.). See for example
qcanvas.sip or qdir.sip (which are QList examples IIRC) in PyQt or
kkeyentrymap.sip in PyKDE2 - the second %MappedType in the file is
a QMap conversion and uses QString. QString converts a little
differently than most other object types.

So, for example, if you have:

QDict<char> foo ();

You need to do:

%MappedType nameOfMappedType
...
%End

and then in the sip file replace QDict<char>:

nameOfMappedType foo ();

The %MappedType definition can be anywhere in the sequence of files
- sip doesn't need to see it before it's used, it just needs to
find it in the same file set somewhere. You can put it in the same
sip file as foo () (which is what Phil usually does) or create a
separate file (which is what I usually do).

If you post the the template (QDict<???>) I can write an example
and post it here.

Jim





More information about the PyQt mailing list