QT对话框
模态对话框
//模态对话框
QDialog dlg(this);//栈上堆栈,exec阻塞,因此不会被释放掉
dlg.exec();//阻塞
非模态
使用完后会被自动释放掉,因此show一闪而过
QDialog dlg2(this);
dlg2.show();
修改:
new的对象不会被自动释放掉,父亲为this,主窗口关闭后才会被释放,因此次数多了可能内存泄漏,
QDialog *dlg2 = new QDialog(this);//创建堆区
dlg2->show();
dlg2->setAttribute(Qt::WA_DeleteOnClose);
错误对话框
QMessageBox::critical(this,"critical","hey");
信息对话框
QMessageBox::information(this,"critical","hey");
if(QMessageBox::Save == QMessageBox::question(this,"save","save",QMessageBox::Save|QMessageBox::Cancel,QMessageBox::Cancel))
{
qDebug()<<"save";
}else{
qDebug()<<"no";
}