我有QObject的QVector QVector<QWidget*> question_vector;
。这些小部件是问题。 (我的申请就像问卷调查一样)。访问存储在QVector中的QObject的方面
当创建问卷时,问题类型从comboBox上的选择中选择,并且在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是小工具,标题,titleEdit,评论,commentsEdit。 如何访问,例如widget的单个组件的文本,commentsText QLineEdit?
你已提出类似的问题:http://stackoverflow.com/questions/41098139/mainpulating-a-qobject-created-from-a-button-press并得到答案。什么是你的问题? –
是的,有一个line_edit_vector [索引] - >文本();获取QVector的文本 line_edit_vector;所以现在即时通讯和QVector question_vector;因为不同类型的小部件正在被添加,而不仅仅是lineedits,所以如果我在question_vector [3]的对象中有一个lineedit,我如何从中获取信息? question_vector [3] - > commentsText->文本();不起作用 –
Phauk