我的代码如下:
MyDialog::MyDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::MyDialog)
{
ui->setupUi(this);
QTimer *timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(Disapper()));
timer->start(2400);
sleep(1);
qDebug()<<"hh";
}
void MyDialog::Disapper()
{
qDebug()<<"we";
reject();
}
输出台:
hh
we
MyDialog是一个对话框,在外面被以模态exec()调用,2.4s后自动关闭,为什么槽函数没有立即执行,而是先执行输出hh才输出we?