MetaType class reference
[Base module]

Declaration  

#include <QtLua/Value>

namespace QtLua {
template <typename X> class MetaType;
};

This class is a member of the QtLua namespace.

This abstract template class is declared in QtLua/qtluametatype.hh source file, line 82.

This abstract template class contains pure virtuals.

Description  

This class can be used to register conversion functions used by QtLua to convert between Lua values and C++ types registered as Qt meta types. It enables use of user defined types for QObject properties and slot parameters.

Consider the following user defined struct and QObject properties:

// code from examples/cpp/types/myobject.hh:32

struct Mystruct
{
int a;
int b;
};

class MyQObject : public QObject
{
Q_OBJECT;
Q_PROPERTY(Mystruct mystruct READ mystruct WRITE setMystruct);
Q_PROPERTY(QMainWindow* mainwindow READ mainwindow WRITE setMainwindow);

The following code shows how to write conversion handler class to handle the Mystruct C++ type as a table value on the lua side:

// code from examples/cpp/types/myobject.hh:41

QTLUA_METATYPE(MyStructConvert, Mystruct);

QtLua::Value MyStructConvert::qt2lua(QtLua::State *ls, const Mystruct *qtvalue)
{
QtLua::Value luavalue(QtLua::Value::new_table(ls));
luavalue[1] = qtvalue->a;
luavalue[2] = qtvalue->b;
return luavalue;
}

bool MyStructConvert::lua2qt(Mystruct *qtvalue, const QtLua::Value &luavalue)
{
qtvalue->a = luavalue.at(1);
qtvalue->b = luavalue.at(2);
return true;
}

The conversion handler and the Qt meta type will be registered on class instantiation:

// code from examples/cpp/types/meta.cc:30

MyStructConvert mystruct_converter;

Moreover, a template class with builtin conversion functions is available to readily handle QObject pointer cases:

// code from examples/cpp/types/meta.cc:33

MyQMainwindowConvert qmainwindow_converter;

See also qRegisterMetaType, QTLUA_METATYPE macro, QTLUA_METATYPE_ID macro and QTLUA_METATYPE_QOBJECT macro.

Members  

Protected functions  

Private function  

Private fields  

Macros  

Members detail  

MetaType(int type)  

This constructor is declared in QtLua/qtluametatype.hh source file, line 88.

This member access is protected.

Register a conversion handler for an already registered Qt meta type.

MetaType(const char *type_name)  

This constructor is declared in QtLua/qtluametatype.hh source file, line 92.

This member access is protected.

Register a conversion handler and qt meta type (using the qRegisterMetaType function).

MetaType()  

This constructor is declared in QtLua/qtluametatype.hh source file, line 146.

This member access is private.

~MetaType()  

This destructor is declared in QtLua/qtluametatype.hh source file, line 95.

This member access is protected.

Unregister conversion handler

#define QTLUA_METATYPE(name, typename_)  

This macro is declared in QtLua/qtluametatype.hh source file, line 107.

This macro defines a type conversion handler class. Class instantiation will also take care of registering the meta type to Qt.

This macro expands to:

struct name
: public QtLua::MetaType<typename_>
{
name()
: QtLua::MetaType<typename_>(#typename_) {}

inline QtLua::Value qt2lua(QtLua::State *ls,
typename_ const * qtvalue);
inline bool lua2qt(typename_ *qtvalue,
const QtLua::Value &luavalue);
};

See also MetaType class.

#define QTLUA_METATYPE_ID(name, typename_, typeid_)  

This macro is declared in QtLua/qtluametatype.hh source file, line 122.

This macro defines a type conversion handler class for an existing Qt meta type id.

This macro expands to:

struct name
: public QtLua::MetaType<typename_>
{
name()
: QtLua::MetaType<typename_>((int)typeid_) {}

inline QtLua::Value qt2lua(QtLua::State *ls,
typename_ const * qtvalue);
inline bool lua2qt(typename_ *qtvalue,
const QtLua::Value &luavalue);
};

See also MetaType class.

#define QTLUA_METATYPE_QOBJECT(name, class_)  

This macro is declared in QtLua/qtluametatype.hh source file, line 139.

This macro defines a type conversion class along with its handler functions able to convert QObject pointers values. The class_ parameter is the bare class name without star.

This macro expands to:

typedef QtLua::MetaTypeQObjectStar<class_> name;

See also MetaType class.

int _type  

This variable is declared in QtLua/qtluametatype.hh source file, line 147.

This member access is private.

const char *_typename  

This variable is declared in QtLua/qtluametatype.hh source file, line 148.

This member access is private.

virtual bool lua2qt(X *qtvalue, const Value &luavalue) = 0;  

This pure virtual function is declared in QtLua/qtluametatype.hh source file, line 103.

This member access is protected.

This function must be implemented to converts a lua value to a C++ value.

The return value is true on success.

virtual Value qt2lua(State *ls, const X *qtvalue) = 0;  

This pure virtual function is declared in QtLua/qtluametatype.hh source file, line 99.

This member access is protected.

This function must be implemented to converts a C++ value to a lua value.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 16:23:03 2013 using MkDoc