1. connect函数
Qt中的connect函数是在Object类中的,作用是把信号与槽连接起来。
connect(sender,SIGNAL(signal()),receiver,SLOT(slot()));
2. 信号与槽的连接
一个信号可以连接多个槽,当信号发射时,会以不确定的顺序一个接一个的调用各个槽;
信号可以连接同一个槽,即无论是哪一个信号被发射,都会调用这个槽;
信号之间可以相互连接
3. connect的应用
//connect.cpp
#include "fatherdialog.h"
#include "ui_fatherdialog.h"
#include <QMessageBox>
FatherDialog::FatherDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FatherDialog)
{
ui->setupUi(this);
QObject::connect(ui->childB,
&QPushButton::clicked,
this,
&FatherDialog::showChildDialog);
}
FatherDialog::~FatherDialog()
{
delete ui;
}
void FatherDialog::on_pushButton_clicked()
{
QMessageBox::information(this,"提示","<font size='26'>请告诉我为什么</font>",QMessageBox::Ok);
}
void FatherDialog::showChildDialog()
{
QDialog * d= new QDialog(this);
d->show();
}
//myconnect.pro
//main.cpp
#include <iostream>
using namespace std;