[C++-sig] boost/python 2.3 + Qt -- Just a tip

Benjamin Collar collar at gamic.com
Mon Dec 1 13:33:48 CET 2003


Greetings

I thought I'd offer a small tip to developers who use a combination of Qt and 
Python and boost. The word 'slots' is used by Qt (3.2.2) and is #defined to 
be empty when a certain macro is not defined.

====== (qt3/include/qobjectdefs.h:74)
...
#ifdef QT_MOC_CPP
#define slots                       slots
#define signals             signals
...
#else
#define slots                                   // slots: in class // line 88
#define signals protected                       // signals: in class
#ifndef QT_NO_EMIT
#define emit                                    // emit signal
#endif
======

The problem occurs when the developer includes headers from Qt before headers 
from boost or Python. In Python's object.h, there's this:

====== (python2.3/include/object.h:331)
typedef struct _heaptypeobject {
        /* Note: there's a dependency on the order of these members
           in slotptr() in typeobject.c . */
        PyTypeObject type;
        PyNumberMethods as_number;
        PyMappingMethods as_mapping;
        PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
                                          so that the mapping wins when both
                                          the mapping and the sequence define
                                          a given operator (e.g. __getitem__).
                                          see add_operators() in 
typeobject.c . 
*/
        PyBufferProcs as_buffer;
        PyObject *name, *slots;
        /* here are optional user slots, followed by the members. */
} PyHeapTypeObject;
======

If you include Qt files before anything from Python then you're the lucky 
winner of a syntax error. If you include everything boost before Qt then 
there's no problem.

Ben

-- 
----------------------------------------

(o__      Benjamin Collar
//\          GAMIC mbH  ++49 (0)241 889 110
V_/_      Developer/System Administrator 

To know recursion, you must first know recursion





More information about the Cplusplus-sig mailing list