On 3 September 2012 15:01, Michael Kirsch <
mkirs...@gmail.com> wrote:
> On Monday, September 3, 2012 4:39:32 AM UTC-4, Michal Kottman wrote
>>
>>
>> This enables public access from Lua to all protected methods, am I
>> correct?
>
>
> Yes, but I don't really have a problem with that, since Lua doesn't have the
> concept of private/protected/public. I think it's better to trust the
> programmer not to use them poorly than to be missing functionality.
I agree, I was just asking :)
>> Lqt already has a simple principle how to
>> access the parent protected method you are overriding using a hack -
>> error(SUPER).
>
>
> But that's just a really ugly hack, and it doesn't let you run code *after*
> calling the base implementation.
True, even the commit of this function says it is a hack :)
>> Could you add a few Lua tests demonstrating what you can do with this
>> approach?
>
> I'm working on an auto-scrolling QTextEdit example that makes use of it, and
> is as far as I can tell impossible to properly implement in the normal lqt.
> The problem is that conecting signals to functions if kind of broken, and
> often gives errors like these:
>
> Object::connect: No such slot QScrollBar::LQT_SLOT_1(int)
How are you calling this? That may be important, this is the first
time I actually see this kind of error. My guess is that you are
trying to create the slot on an object that was not created by Lua
(QScrollBar.new).
> Am I doing something wrong? I found the connect source code, and can't
> figure out why it would fail like this.
The source code (the creation of given scroll bar, and the actual
call) would be helpful to find out what is happening.
> Another thing is that, for example, "QTextEdit.resizeEvent", works, but
> "QTextBrowser.resizeEvent" doesn't. Does lqt not support looking in base
> classes if lookup fails?
Yes it does, in this case I am not sure what exactly causes the
problem, but in "base lqt" QTextEdit.resizeEvent does not exist, so
QTextBrowser.resizeEvent should neither. Also, inheritance is
implemented on objects, not on classes. Therefore if you have:
local tb = QTextBrowser()
print(tb.alignment) -- function: 0xXXXXXXXX
print(QTextBrowser.alignment) -- nil
Note that on my installation, tb.resizeEvent is also nil.
> I am also working on improving connect to accept "methods" of Lua "objects":
>
> myqobject:connect('2some_signal(int)', myobject, myobject.mymethod)
>
> This will call <myobject.mymethod>(<myobject>, <signal args>) when the
> signal is emitted.
This was supposed to work by using closures instead:
myobject:connect('2somesignal(int)', function(...)
myobject:mymethod(...) end)
Note that you cannot use signatures not already available in existing
signals - this means that you cannot create new signal signatures
(there is one big class called SlotAcceptor which implements all known
slot signatures and dispatches to Lua).
> And finally, there's another big problem in lqt that I would like to
> mention: the way it handles enums. It converts them to and from strings, but
> not everywhere. In places where it doesn't, the constants aren't available,
> so I have to hardcode the numbers. Why not just throw away the idea of using
> strings for enums, and expose the constants (like Qt.DisplayRole == 0, for
> example) directly to Lua?
They already exist like numbers, but they are one level deep -
Qt.ItemDataRole.DisplayRole == 0
To search for such names - look at documentation (see the enum name),
or this in Lua:
for k,v in pairs(Qt) do for kk,vv in pairs(v) do if kk ==
'DisplayRole' then print(k, kk, vv) end end end
> I know this would break existing lqt programs, but IMO it would be a huge
> improvement that would be worth it when writing new programs.
The longer I think about it, the more I am assured of the fact that
Lqt needs a complete reimplementation (but minimizing the differences
from script size).