从 QDialog 获取值

Get values from a QDialog

本文关键字:获取 QDialog      更新时间:2023-10-16

我有一个QDialog,它有两个行编辑和一个按钮。按下按钮时,我希望关闭 QDialog,并且我希望行编辑中的值可供我使用。现在,我有以下内容:

void createDialog()
{
    QDialog dialog;
    QLineEdit *lineEdit1 = new QLineEdit(&dialog);
    QLineEdit *lineEdit2 = new QLineEdit(&dialog);
    QPushButton *ok = new QPushButton("OK", &dialog);
    QVBoxLayout *vLayout = new QVBoxLayout();
    vLayout->addWidget(lineEdit1);
    vLayout->addWidget(lineEdit2);
    vLayout->addWidget(ok);
    dialog.setLayout(vLayout);
    connect(ok, SIGNAL(clicked()), this, SLOT(processValues()));
    dialog.exec();
}

我想知道如何关闭QDialog并在processValues()函数中访问lineEdits的值。谢谢!

你应该从QDialog进行子类化,并将所有小部件放在那里。QLineEdits将成为Dialog的成员,它将具有成员函数,这些函数将返回这些函数的值。

您可以在 http://thisthread.blogspot.com/2010/06/qdialog-subclass.html 在此处查看示例。这里 http://www.informit.com/articles/article.aspx?p=1405224

如何从QDialog传递数据?