QT widget 以阻塞的模态形式打开

需求 需要把 widget 以模态形式打开,组织用户操作前一个页面。 解决 QWidget 没有 exec 这个方法,只能转化为 QDialog 之后,再使用 exec 方法。 CurrentGetConfigForm * current_get_config_form = nullptr; void MainWindow::on_pushButton_current_get_config_clicked() { if (!GetConfig()) return; if (current_get_config_form == nullptr) current_get_config_form = new CurrentGetConfigForm(nullptr, port_, version_, address_); current_get_config_form->setAttribute(Qt::WA_ShowModal, true); current_get_config_form->setAttribute(Qt::WA_DeleteOnClose, true); current_get_config_form->show(); //QEventLoop loop; //loop.exec(); qDebug() << "MainWindow::on_pushButton_current_get_config_clicked() end" << Qt::endl; current_get_config_form = nullptr; } 参考 QWidget如何exec QT 创建新窗口并且实现页面跳转 qt 增加新窗口,并显示在最前

2023-05-25 · 1 min · 59 words · RamLife