【问题标题】:Get values from a QDialog从 QDialog 获取值
【发布时间】:2013-10-05 20:19:45
【问题描述】:

我有一个 QDialog,它有两个 lineEdits 和一个按钮。按下按钮时,我希望 QDialog 关闭,并且我希望 lineEdits 中的值可供我使用。现在,我有以下几点:

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 的值。 谢谢!

【问题讨论】:

    标签: c++ qt qt4


    【解决方案1】:

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

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

    How to pass data from a QDialog?

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多