Expression qt.qcall(qobject, f, ...) executes function f from the thread owning the Qt object qobject. To achieve this, the current thread performs a rendez-vous with the object thread. The object thread takes ownership of the Lua data structures and invokes function f with the specified arguments. Meanwhile the original thread processes events and waits. When the function f returns, the original thread resumes the execution.

Like the standard Lua function pcall, this function returns multiple results. If an error occurs during the execution, this function returns false plus the error message. Otherwise it returns true plus the results returned by function f.

This function is the basis for the thread hopping mechanism that underlies the multi-thread operations in QtLua. Thread hopping happens automatically whenever one manipulates a slot or a property of a Qt object. It may occasionnally be useful to manually hop into an object thread in order to avoid the overhead of subsequent thread hopping operations: if the Lua interpreter is already running in the desired thread, the function f can be invoked directly without expensive synchronization.

Important : Thread hopping only works if the target thread runs an event loop, using QThread::exec() or QEventLoop::exec(). Execution of Lua program will stop if this is not the case.

Within program qlua, object qt.qApp is always owned by the main thread in charge of the user interaction, and object qt.qEngine is always owned by the auxilliary thread in charge of the evaluation of Lua expressions.