Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling the base class #9

Closed
henux opened this issue Sep 7, 2011 · 1 comment
Closed

Calling the base class #9

henux opened this issue Sep 7, 2011 · 1 comment

Comments

@henux
Copy link
Contributor

henux commented Sep 7, 2011

Hi.

Is it possible to call the base class method from an overloaded virtual method somehow? Such as,

foo = QTextEdit()
function foo:keyPressEvent(e)
    -- do something
    super.keyPressEvent(e)
end

This would be necessary for overloading some event handlers.

Also, binding the global namespace enums somehow would be useful. Such as,

function foo:keyPressEvent(e)
    if e:key() == Qt.Key_Enter then
        -- enter was pressed
    end
end
@mkottman
Copy link
Owner

mkottman commented Sep 7, 2011

I have fought with the need to call super virtual methods too, however I found no clean and concise way of doing it (I would also need to export protected virtual functions, which I could do, but do not want to).

Currently, you can use this to call the virtual method with original parameters:

function foo:keyPressEvent(e)
    -- do something
    error(SUPER) -- not nice, but...
end

As for the second point, you have to look a bit deeper:

function foo:keyPressEvent(e)
    if e:key() == Qt.Key.Key_Enter then
        -- enter was pressed
    end
end

That means you have to enter the enum name between Qt and value. I use the following function to quickly find an enum I'm looking for:

function findEnum(name)
    name = name:lower()
    require 'qtcore'
    require 'qtgui'
    for k,v in pairs(Qt) do
        for kk,vv in pairs(v) do
            if type(kk) == 'string' and kk:lower():match(name) then
                print('Qt.' .. k .. '.' .. kk .. ' = ' .. vv)
            end
        end
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants