Expression qt.connect(qobject, signature, func) connects the signal signature from Qt object qobject to the Lua function func. Argument signature is a string containing the full signature (c++ prototype) of the signal. The function is invoked whenever the signal is emitted.

Example:

require 'qt'
timer = qt.QTimer()
timer.singleShot = true
qt.connect(timer,'timeout()', function() print("timeout") end)
timer:start(2000) -- wait for 2 seconds...

See section Receiving Signals for more details.

Warning : Function func remains allocated as long as the connection exists. Memory can be leaked if function func is a closure that points to the signaling object because the garbage collector will find that the object is in use. Future versions of QtLua may address this weakness of the interface between the Lua garbage collector and the Qt static memory allocation. In the mean time, be careful to delete or disconnect connected objects as soon as you do not need them anymore.