Mon 18 Jun 2012 10:09:23 AM UTC, original submission:
Hello!
I'm sorry for disturbing you so often! Using QtLua I've met the following issue. It would be convenient to use qt.connect() function when using Lua function as a SLOT with explicitly set "self" element.
In other words text such as:
ui = qt.load_ui( "form.ui" )
ui:show()
t = { stri = "Hi!" }
function t:func()
print( tostring( self.stri ) )
end
qt.connect( ui.button01, "clicked", t, t.func )
at the moment is impossible, because sender() object is put as it's self element around line 150 in "qtluaqobjectwrapper.cc" and hardcoded. And one is to analyze it to understand what data should be used with particular slot call if one and the same Lua function is used. And one should care about keeping the data which should be used during slot call somewhere... may be in global variable...
I've extended QtLua::QObjectWrapper::LuaSlot with "_self" field, changed it's constructor and a bit modified "qt.connect()" and "_lua_connect()" function's code in order to get the result.
After modifications all "qt.connect()" implementations accept 4 arguments. First 2 are as before. In the case of Lua SLOT 3-rd one is "self" variable which will be substituted instead io hard coded "sender()". And the 4-th one is Lua function itself.
In order to get original functionality one should just make 3-rd and 1-st arguments the same.
I've attached the code with modifications. I hope it makes sense.
|