[Kde-bindings] custom slots
Thomas Moenicke
tm at ippfp.org
Fri Jan 27 11:05:38 UTC 2006
Richard Dale wrote:
> Another way is to override the QObject::metaObject() virtual method in php
> subclasses of the QObject classes, and return a dynamically constructed
> QMetaObject with any slots and signals that were defined in php. Then
> override the qt_metacall() virtual method, and for any php slots marshall
> the args from C++ to php, and call the php method. If the qt_metacall()
> wasn't for a php slot, then call qt_metacall() in the super class, so that
> it will just call an existing C++ slot. Given a list of slot and signal
> type signatures as strings it is reasonably straightforward to construct a
> QMetaObject.
Everything ok, but how to define such a metaobject at runtime? Or more
precisely how to add slots defined as php methods to a metaobject? Here I
have the same problem as descibed in my previous mail, or am I wrong with
that?
> The disadvantage of using proxy methods is that you need to intervene
> everytime a slot or signal is passed to a Qt method, and do something
> different depending on whether the target slot is a C++ on or a php one.
> Whereas if you construct QMetaObjects at runtime from the slots and signals
> declared in php, you only need to override the qt_metacall() method.
Ok. Lets point that out, this is a copy of my experiment:
int Bridge::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: { int _r = check_signal(*reinterpret_cast< int*>(_a[1]));
if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; } break;
// case 1: check_slot(*reinterpret_cast< int*>(_a[1])); break;
case 1: (this->*slot_functions[0])(*reinterpret_cast< int*>(_a[1]));
break;
}
_id -= 2;
}
return _id;
}
qt_metacall looks up in any data structure where a pointer to the php function
is stored. Therefor I need to register the right id for this custom slot.
Well, I can override qt_metacall, but it will only be called if Qt finds a
name of the slot in their data structures.
Now the question is how to construct metaobjects at runtime, with the names of
all custom slots inside.
> Given a list of slot and signal
> type signatures as strings it is reasonably straightforward to construct a
> QMetaObject.
Thus, modify this?
static const uint qt_meta_data_Bridge[] = {
// content:
1, // revision
0, // classname
0, 0, // classinfo
2, 10, // methods
0, 0, // properties
0, 0, // enums/sets
// signals: signature, parameters, type, tag, flags
21, 12, 8, 7, 0x05,
// slots: signature, parameters, type, tag, flags
45, 39, 7, 7, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_Bridge[] =
{ "Bridge\0\0int\0newValue\0check_signal(int)\0value\0check_slot(int)\0myownstuff\0"
};
--
Thomas
More information about the Kde-bindings
mailing list