[Qt-interest] QtScript segfault on C++ signal (dis)connection/firing

Kent Hansen khansen at trolltech.com
Thu Jan 15 18:13:43 CET 2009


Hi Sean,

Sean M. Pappalardo wrote:
> Hello again.
>
> Kent Hansen wrote:
>   
>> Hi Sean,
>> Any chance that the same script engine is being accessed from multiple
>> threads? 
>>     
>
> That's actually almost certain. I'm pretty sure the emitting object is
> in a different thread than where the engine was instantiated.
>
>   
>> QtScript is not thread-safe, so be sure that there's only a
>> single thread evaluating code (unless you've explicitly added a
>> synchronization mechanism),
>>     
>
> A single thread ever or one thread at a time?
>   

One thread at a time per QScriptEngine. This also applies to operations
on QScriptValues (e.g. QScriptValue::call()), since those values are
bound to a particular engine.

>   
>> and make sure that all connections are
>> queued.
>>     
>
> Signal connections? Can you point me to info on how to do that? (I'm
> relatively new to C++.)
>
> Thank you again very much for your time! This information will help alot!
>   

Connections created with QtScript (e.g. qScriptConnect()) are
auto-connections; see
http://doc.trolltech.com/4.4/qt.html#ConnectionType-enum.
If multiple threads are emitting signals to be caught by a single script
engine, you should ensure that the objects emitting the signals don't
live in the script engine thread, and ensure that calls to
QScriptEngine::evaluate() (or any other operation that can have a
side-effect on the engine, e.g. QScriptValue::toString()) are done from
the script engine thread (or synchronized properly -- but I recommend
the queuing approach). See http://doc.trolltech.com/4.4/threads.html and
http://doc.trolltech.com/4.4/qobject.html#moveToThread.

Regards,
Kent



More information about the Qt-interest-old mailing list