我有一个 QVector 的 QObjects QVector<QWidget*> question_vector;
。这些小部件是问题。(我的申请就像一个问卷调查)。
创建问卷时,从组合框中的选择中选择问题类型,在 Questions 类中,问题被创建并存储在 QVector 中。
void CreateSurvey::comboBox_selection(const QString &arg1)
{
if(arg1 == "Single Line Text")
{
Question *singleLineText = new Question("Single Line Text");
surveyLayout->addWidget(singleLineText);
question_vector.append(singleLineText);
qDebug() << "Number of items: "<< question_vector.size();
} ...
}
void Question::create_singleLineEdit()
{
QVBoxLayout *vLayout = new QVBoxLayout;
QLabel *titleLabel = new QLabel("Title");
vLayout->addWidget(titleLabel);
QLineEdit *inputText = new QLineEdit;
vLayout->addWidget(inputText);
QLabel *commentsLabel = new QLabel("Comments");
vLayout->addWidget(commentsLabel);
QLineEdit *commentsText = new QLineEdit;
vLayout->addWidget(commentsText);
ui->frame->setLayout(vLayout);
}
SingleLineEdit 是widget,title,titleEdit,comments,commentsEdit。如何访问,例如来自小部件的单个组件的文本,commentsText QLineEdit?