[Top][All Lists]

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

Re: [Libqtlua-list] Accessing QObject inside a property in Lua

From: Gustavo de Sá Carvalho Honorato
Subject: Re: [Libqtlua-list] Accessing QObject inside a property in Lua
Date: Tue, 11 Jan 2011 23:03:08 -0200

On Tue, Jan 11, 2011 at 9:56 PM, Alexandre Becoulet
<address@hidden> wrote:
> On Tuesday, January 11, 2011 03:27:53 pm Gustavo de Sá Carvalho Honorato
> wrote:
> Hi,
>> I'm trying to access my MainWindow class throught a property which is
>> declared inside my Application class in Lua. I've declared the
>> MainWindow using Q_DECLARE_METATYPE(MainWindow*) and
>> qRegisterMetaType<MainWindow*>(). I've exposed my application class
>> using state["app"] = QtLua::Value(state, qApp, false).
>> The problem occurs when I try to access the MainWindow by typing
>> app.mainWindow:close() in Lua Console, and I got the error "error:
>> [string ""]:1: attempt to index field 'mainWindow' (a nil value)".
>> It's quite weird because when I type list(app) I can see that the
>> property mainWindow has a value QtLua::Property<MainWindow*>
>> mainWindow = Application::mainWindow.
> QtLua has no way to guess how to convert your declared meta type to a
> QtLua::Value. Try using a QObject* or QWidget* instead of a MainWindow*
> pointer type.

Sorry, I gave you an incomplete information. MainWindow inherits from
QMainWindow which inherits from QWidget. I've registered MainWindow*
type because when I tried to access mainWindow property, I was getting
"QMetaProperty::read: Unable to handle unregistered datatype" error.

> Lua/Qt values convertion on property access and method call is performed by
> raw_get_object and raw_set_object in src/ Supporting dynamic
> declaration of new types would require registering two callbacks to implement
> value convertion, I can implement this if there is a real need.

It is necessary only for types which not inherits from QObject, am I
right? Implementing this will enable custom defined types with
QT_DECLARE_METATYPE to be handled in Lua code, is it?

> --
> Alexandre

reply via email to

[Prev in Thread] Current Thread [Next in Thread]