正确的做法:
1、
FormProcessRoi *form = new FormProcessRoi(this);//只能用指针,不能实例化为对象 //Qt::NonModal 不阻塞 //Qt::WindowModal 阻塞父窗口,所有祖先窗口及其子窗口 //Qt::ApplicationModal 阻塞整个应用程序 form->setWindowModality(Qt::ApplicationModal); //设置阻塞类型 form->setAttribute(Qt::WA_ShowModal, true); //属性设置 true:模态 false:非模态 form->setWindowFlags(Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::Dialog); form->show();
2、
FormAbout *a = new FormAbout(nullptr); //不能有父类
a->setAttribute(Qt::WA_ShowModal, true); //属性设置true:模态;false:非模态
a->setWindowTitle(tr("关于本软件"));
a->setWindowIcon(QIcon(":/res/icons/main.png"));
a->setWindowFlags(/*a->windowFlags()|*/ Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::Tool); //使得任务栏不会有该窗口的图标
a->show();
错误的做法:
FormProcessRoi form;
form.show();