1、connect()函数实现的是信号与槽的关联。
注意:只有QO bject类及其派生的类才能使用信号和槽的机制
2、函数原型
static QMetaObject::Connection connect(const QObject *sender, const char *signal,const QObject *receiver, const char *member, Qt::ConnectionType = Qt::AutoConnection);
static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,const QObject *receiver, const QMetaMethod &method,
Qt::ConnectionType type = Qt::AutoConnection);
inline QMetaObject::Connection connect(const QObject *sender, const char *signal,const char *member, Qt::ConnectionType type = Qt::AutoConnection) const;
在第一个函数中:第一个参数为发射信号的对象,例如后面的dlg;第二个参数是要发射的信号,例如后面的SIGNAL(dlgReturn(int));
第三个参数是接受信号的对象,例如后面的this,表明是本部件,即Widget,当这个参数是this时,可以将其省略掉,因为在第三个函数中,该参数默认为this;第四个参数是要执行的槽,例如
后面的SLOT(showValue(int)),也可以指定一个信号,实现信号与信号的关联。
eg:
MyDialog *