Qt中信号和槽执⾏的顺序执⾏特性
1. 因为signal-slot本⾝是⼀个顺序执⾏的过程,只有执⾏完slot之后,才会执⾏emit的下⼀条语句。
2. 如果使⽤队列连接⽅式,则在emit信号后,先执⾏emit语句后⾯的代码,执⾏完成后再执⾏对应的槽函数;
思想政治教育研究3. 代码实例:王旁
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
心理健康教育专业ui(new Ui::Widget)
{
ui->tupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(slot1())/*, Qt::QueuedConnection*/);
connect(this, SIGNAL(signal1()), this ,SLOT(slot2()));//info1
connect(this, SIGNAL(signal1()), this ,SLOT(slot2()), Qt::QueuedConnection);//info2
/*
*
* info1:emit信号发出后,先执⾏槽函数,再执⾏emit后⾯的语句;
* info2:emit信号发出后,使⽤队列连接信号和槽,这个时候,先执⾏emit后⾯的语句,在执⾏槽函数
* info:[
emit signal1()
enter slot2自评报告
start to enter slot2()s
];
info2:[冰箱保鲜温度
emit signal1()
start to enter slot2()s
enter slot2
]
红烧羊肉汤*/
}
Widget::~Widget()
{
delete ui;
}
void Widget::slot1()
{
烟花散
qInfo() << "emit signal1()";
emit signal1();
qInfo() << "start to enter slot2()s";
}
void Widget::slot2()
暑假英语怎么说{
qInfo() << "enter slot2";
}