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();
}

 

posted @ 2020-03-05 22:10  朱小勇  阅读(897)  评论(0编辑  收藏  举报