Qt对话框弹出问题 若要临时弹出一个对话框(类似QMessageBox),此处提供一种方法(不会存在内存泄漏). QDialog dialog; QHBoxLayout *hbox = new QHBoxLayout; QHBoxLayout *hbox2 = new QHBoxLayout; QLabel *serverIpLabel = new QLabel(tr("服务器IP:")); QLineEdit *lineEidt = new QLineEdit; QPushButton *confirm = new QPushButton(tr("确认")); QPushButton *cancel = new QPushButton(tr("取消")); connect(cancel, &QPushButton::clicked, &dialog, dialog.close); hbox->addWidget(serverIpLabel); hbox->addWidget(lineEidt); hbox2->addWidget(confirm); hbox2->addWidget(cancel); QVBoxLayout *vbox = new QVBoxLayout; vbox->addLayout(hbox); vbox->addLayout(hbox2); dialog.setLayout(vbox); dialog.exec();