[PyQt] Function pointers and SIP

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jun 18 19:01:31 BST 2009


On Thu, 18 Jun 2009 19:40:08 +0200, Giovanni Bajo <rasky at develer.com>
wrote:
> Hi Phil,
> 
> given a C++ object where you can register callbacks such as:
> 
>      void registerCallback(void (*cb)(void*), void* user_data);
> 
> or
> 
>      void registerCallback(std::tr1::function<void (void)> cb);
> 
> how would you wrap them in SIP? Is there some code in PyQt that I can 
> look at?

I think you answered this yourself a couple of weeks back.

You'll tell SIP that the arguments are...

    void registerCallback(SIP_PYCALLABLE cb, SIP_PYOBJECT user_data);

You'll need to provide %MethodCode. How well you wrap it depends on how
well the API is designed. You can wrap it properly if the API provides
enough context information to the callback to allow a single callback to
handle all calls.

The nearest example in PyQt is probably qInstallMsgHandler().

Phil


More information about the PyQt mailing list