lua-users home
lua-l archive

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


On 09/09/2007, Bradley Smith <gmane@baysmith.com> 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:
http://linuz.sns.it/~iazzi/generator.tar.gz

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
work.

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...

mauro

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


app = QApplication.new()
mainwin = QWidget.new()
mainwin:show()
layout = QVBoxLayout.new()

mainwin:setLayout(layout)
mainwin:setWindowTitle'lqt test window'

te = QTextEdit.new()
layout:addWidget(te)
te:setToolTip'I\'m the Code Edit Box: I hold the code while you edit'

te:setPlainText[[
buttons = buttons or {}
i = #buttons + 1

but = QPushButton.new()

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

buttons[i] = but

return 'Created button '..i

]]

pb = QPushButton.new()
layout:addWidget(pb)
pb:setText'Exec'
pb:setToolTip'I\'m the Exec button: push me to execute your code'

quit = QPushButton.new()
layout:addWidget(quit)
quit:setText'Quit'
quit:setToolTip'I\'m the Quit button: push me to close all windows'

results = QLabel.new()
results:setToolTip'I\'m the result bar: I will show you your results
and your errors'
layout:addWidget(results)

pb:connect(qt.signal'pressed()', SLOT(function()
  local f, err = loadstring(te:toPlainText())
  if f==nil then
    results:setText(err)
  else
    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
      end
      results:setText(string)
    else
      results:setText(res[2])
    end
  end
end))
quit:connect(qt.signal'pressed()', app, qt.slot'closeAllWindows()')

app:exec()

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,
}

MyWidget.new = function(...)
local ret = QPushButton.new(...)
debug.setmetatable(ret, MyWidget) -- this will require a C code to be clean
--print(ret, getmetatable(ret), MyWidget )
return ret
end

b = MyWidget.new()

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