lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 09/09/2007, Bradley Smith <> wrote:
> Unfortunately, it does not work with Qt 4.1.0 on Windows.

I strongly  think that this portability of the generated code is not
really reachable.

For such different systems you should start from generator and do the
bindings yourself.
Actually, this requires the use of gccxml, so you can be out of luck...

Given that at least two persons could want to see it, the generator is here:

Be advised that you could not like what you will see :)

I run dofile'test.lua' after having set the string on top to the list
of classes I want to bind.
I tried to keep any Qt4-specific code in test.lua, but there is also
generic code there, which should have finished in binder.lua.

Obviously, no documentation yet. I have some clues, anyway:
 - it uses Lua Expat, you'll have to get it.
 - you could have to mess with inclusions to have it all working, in
Qt4 things are quite simple.
 - common_bind.hpp (in the "tutorial") is to be included in every file
 - change it to reflect your build of Lua (extern "C" or not)
 - getting and pushing custom types is shown at the top of test.lua,
where QStrings are set to be transparently changed into Lua strings.
 - throwing an error in binder.lua usually means no binding for the
current function and is quite safe. I use this.
 - you could have to mess with accesses. My current policy is to bind
only public functions, and they are more than 250 for QWidget only.

As for Windows, I cannot say. You could have to make it compile in a
parallel linux/unix environment with the same version of Qt. Throwing
errors if you encounter X11 specific function/type names will avoid
you binding those (in binder.lua), and could be enough to make it

If it still does not work, you could try and strip also the bindings
for all names containing an underscore. Those are actually meant to be
internal, and could be platform-specific.
In an extreme try, I could actually make the XML in my computer and
send it to you. This would require compiling an older version of Qt
here, so if there is an alternative, it would be better.

If you actually try it, keep me informed of the results, please.

Hope this helps...


PS: for a little code sample, the main window of the video is created
in Lua, like this:

app =
mainwin =
layout =

mainwin:setWindowTitle'lqt test window'

te =
te:setToolTip'I\'m the Code Edit Box: I hold the code while you edit'

buttons = buttons or {}
i = #buttons + 1

but =

but:connect(qt.signal'pressed()', but, qt.slot'close()')
but:setText'Close Me!'
but:setWindowTitle('Button '..i)
but:setFixedSize(180, 50)
but:setFont('Times', 18, 75))

buttons[i] = but

return 'Created button '..i


pb =
pb:setToolTip'I\'m the Exec button: push me to execute your code'

quit =
quit:setToolTip'I\'m the Quit button: push me to close all windows'

results =
results:setToolTip'I\'m the result bar: I will show you your results
and your errors'

pb:connect(qt.signal'pressed()', SLOT(function()
  local f, err = loadstring(te:toPlainText())
  if f==nil then
    local res = { pcall( f ) }
    if res[1] then
      local string = ''
      for i, r in ipairs(res) do
        if i~=1 then string = string .. tostring(r) .. ', ' end
quit:connect(qt.signal'pressed()', app, qt.slot'closeAllWindows()')


and inheritance looks like this, the virtual function event is
overloaded with print

MyWidget = {
event = print,
__base = { QPushButton=QPushButton },
__index = QPushButton.__index,
__newindex = QPushButton.__newindex,
} = function(...)
local ret =
debug.setmetatable(ret, MyWidget) -- this will require a C code to be clean
--print(ret, getmetatable(ret), MyWidget )
return ret

b =

print(b, b.__index, '->', type(b.__index(b, "show")))