【发布时间】:2016-12-12 09:55:01
【问题描述】:
我正在制作一个应用程序,并且在某个时候,用户将创建某种形式的来自/调查。创建时,用户通过按下按钮选择各种问题类型等,将创建一个新对象。
创建一个新部分,例如:
void CreateSurvey::question_section()
{
QLabel *sectionTitle = new QLabel();
sectionTitle->setText("New Section");
layout->addWidget(sectionTitle);
QLabel *titleLabel = new QLabel("Title");
QLineEdit *titleEdit = new QLineEdit("New Section");
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(titleLabel);
hLayout->addWidget(titleEdit);
layout->addLayout(hLayout);
sectionCount++;
qDebug() << "sections: " << sectionCount;
}
当应用程序运行时,用户将编辑文本“TitleEdit”作为该部分的标题。 假设这已经被调用了 3 次,所以有 3 个部分。如何获取为每个部分的标题输入的字符串?或者如何获取为特定部分输入的字符串?
谢谢
【问题讨论】:
-
您需要存储您感兴趣的对象。否则您将不会(简单地)访问它们。
-
我该怎么做?在数组中?
-
布局包含您要添加的所有对象。您可以循环并提取您需要的数据。
-
@Phauk:你想要的任何容器。在 Qt 库和 std 中有很多。
-
@bibi,你是什么意思'循环并提取你需要的数据'?我不知道该怎么做