[C++-sig] Can boost.python and PyQt be used together?

David Abrahams dave at boost-consulting.com
Tue Dec 10 19:19:40 CET 2002


"Marcelo A. Camelo" <camelo at esss.com.br> writes:

>>>> Another possible conflict, perhaps more likely, is the two 
>>>> modules fighting over the Qt API.
>
>>> Could you be a little more specific about what this might mean?
>
>> Not really - just an uncomfortable feeling about events being 
>> dispatched from an object wrapped by one module to an object 
>> wrapped by another module that calls a virtual re-implemented 
>> in the first module etc, etc.
>
> I'm having a very similar problem. 
>
> I'm using boost::python to wrap C++/Win32/DirectX code and I'm 
> also using PyQt to create user interfaces. 
>
> In three similar situations I've got the infamous error
> "Fatal Error: Thread state is Null" (or something like that).
>
> I haven't nailed down the bug yet, but I've found that it is 
> related to calling back my C++/Win32/DirectX library (wrapped in 
> boost) from an event triggered from Qt main event loop.
>
> Not every callback will fail. Some Win32 api calls will make it
> fail (SetWindowPos will make it fail, MoveWindow won't). Some 
> DirectX calls also fail (if I comment those calls, everything 
> goes fine).
>
> The error is generated after the wrapped method call has been 
> completed, but before control is passed back to python.
>
> I've also had some problems related to Win32 message queue. The
> WindowProc message for my own Window Classes is being called 
> from the Qt main event loop. If I dispatch those messages and
> generate events to python code that calls back to my C++ 
> library, bang!!! In this case, I don't know if the crash only
> occurs when making win32 API calls.
>
> Hope this information is of some value.

Is it possible to post code for a small Windows application or
extension, not dependent on Qt, which demonstrates this?

One of the odd things about Windows event loops (and COM, AFAIK) is
that various calls to the OS can cause your event loop to be invoked,
and which calls these are is not documented.  It's possible that some
of the code in Boost.Python or Qt is not "reentrant" in this sense. 

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list