Qt动态生成界面并通过拉姆达获取其返回值
代码:
QDialog* log = new QDialog(this); log->deleteLater(); log->setWindowTitle("新增故障"); log->setGeometry(QCursor::pos().x(),QCursor::pos().y(),200,100); log->setMinimumSize(200,100); QLabel* lel = new QLabel(log); lel->setText("请选择故障码:"); QComboBox* box = new QComboBox(log);box->addItem("123"); QHBoxLayout* hLayout1 = new QHBoxLayout(); hLayout1->addWidget(lel); hLayout1->addWidget(box); QPushButton* okBtn = new QPushButton(log); QPushButton* clsBtn = new QPushButton(log); okBtn->setText("确定"); clsBtn->setText("取消"); QObject::connect(okBtn, &QPushButton::clicked,log,[=]() { log->done(RET_OK); }); QObject::connect(clsBtn,&QPushButton::clicked,log,[=]() { log->done(RET_ERR); }); QHBoxLayout* hLayout2 = new QHBoxLayout(); hLayout2->addWidget(clsBtn); hLayout2->addWidget(okBtn); QVBoxLayout* vLayout = new QVBoxLayout(); vLayout->addItem(hLayout1); vLayout->addItem(hLayout2); log->setLayout(vLayout); if(RET_OK == log->exec()) { qDebug()<<"故障码:"<<box->currentText(); }
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html