Signal & Slot in QT
2014-12-10 19:36
591 查看
Try your best to provide an mechanism to implement what you want.
1. All is generated by QT Framework before compiling.
QObject.connect(sender,SIGNAL(signal()), reciver,SLOT(slot()));
==>
2. Add additional meta data and function in class
3. Define your own macro, translate user input string into the real code
All below is added in order to find the right ID for cooresponding method of signal and slot
Example:
4.And connection object to list
![](http://images.cnitblog.com/blog/414769/201501/181016257142845.png)
![](http://images.cnitblog.com/blog/414769/201501/181016338082952.png)
1. All is generated by QT Framework before compiling.
QObject.connect(sender,SIGNAL(signal()), reciver,SLOT(slot()));
==>
QObject.connect(sender, “2signal( )”,reciver,”1slot()”);
class QExample : public QObject { Q_OBJECT public: QTestA (QObject *parent ); ~QTestA (); signals: void SignalA1 (); void SignalA2 (int i ); public slots: void SlotA1 (); void SlotA2 (char *szBuf ,int nSize ); private: public: int qt_metacall (QMetaObject ::Call _c , int _id , void **_a ) { _id = QObject ::qt_metacall (_c , _id , _a ); if (_id < 0) return _id ; if (_c == QMetaObject ::InvokeMetaMethod ) { switch (_id ) { case 0: SignalA1 (); break ; case 1: SignalA2 ((*reinterpret_cast < int (*)>(_a [1]))); break ; case 2: SlotA1 (); break ; case 3: SlotA2 ((*reinterpret_cast < char *(*)>(_a [1])),(*reinterpret_cast < int (*)>(_a [2]))); break ; default : ; } _id -= 4; } return _id ; } };
2. Add additional meta data and function in class
1 QMetaObject 2 { 3 const QMetaObject *superdata ; 4 const char *stringdata ; //save class name, signal name, parameter name,slot name, all ended by '/0' 5 const uint *data ; //int array, store information of QMetaObjectPrivate 6 }
struct QMetaObjectPrivate { int revision ; int className ; int classInfoCount , classInfoData ; int methodCount , methodData ; int propertyCount , propertyData ; int enumeratorCount , enumeratorData ; int constructorCount , constructorData ; };
3. Define your own macro, translate user input string into the real code
All below is added in order to find the right ID for cooresponding method of signal and slot
Example:
static const uint qt_meta_data_Q QExampleData[] = { 2, // revision 0, // classname 0, 0, // classinfo 4, 12, // methods and its data 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors // 以上部分 是QMetaObjectPrivate 结构信息 // signals: signature, parameters, type, tag, flags 8, 7, 7, 7, 0x05, 21, 19, 7, 7, 0x05, // slots: signature, parameters, type, tag, flags 35, 7, 7, 7, 0x0A, 56, 44, 7, 7, 0x0A, 0 // end };
// slots: signature, parameters, type, tag, flags 1 static const char qt_meta_stringdata_Q QExampleMetaData [] = { "QTestA/0/0SignalA1()/0i/0SignalA2(int)/0" "SlotA1()/0szBuf,nSize/0SlotA2(char*,int)/0" };
4.And connection object to list
QMetaObject::connect(sender, signal_index,receiver, method_index,type, types); QObject *s =const_cast<QObject*>(sender); QObject*r = const_cast<QObject *>(receiver); QOrderedMutexLockerlocker(&s->d_func()->threadData->mutex, &r->d_func()->threadData->mutex); QObjectPrivate::Connection c; c.receiver = r; c.method = method_index; c.connectionType = type; c.argumentTypes= types; s->d_func()->addConnection(signal_index, &c); r->d_func()->refSender(s, signal_index);
![](http://images.cnitblog.com/blog/414769/201501/181016257142845.png)
![](http://images.cnitblog.com/blog/414769/201501/181016338082952.png)
![](http://images.cnitblog.com/blog/414769/201501/181015361512538.jpg)
相关文章推荐
- QT signal & slot 定义及用法 .
- 使用QT中的Signal&Slot机制进行传值
- QT窗体间传值总结之Signal&Slot
- Inside QT Series (七):Signal &amp; Slot
- QT signal & slot 定义及用法
- QT高级编程技巧(一)-- 编写高效的signal & slot通信代码
- Qt:QML:QML于C++交互之信号与槽(signal&slot )
- Qt 初探信号与槽(signal & slot)
- Qt学习笔记:Signal & Slot
- QT signal & slot 定义及用法
- Qt MetaObject System详解之五:signal&slot
- QT signal & slot 定义及用法
- QT窗体间传值总结之Signal&Slot
- qt slot & signal
- QT窗体间传值总结之Signal&Slot
- QT窗体间传值总结之Signal&Slot
- 简单的2个实例,助你理解Qt的自定义Signal & Slot机制
- Qt信号与槽机制(signal & slot)
- QT signal & slot 定义及用法
- QT窗体间传值总结之Signal&Slot