そのため、1 つのタブにスピンボックス (30) の広範なリストがあり、別のタブに確認ページがあります。確認ページに 0 より大きい名前と値のみを表示するにはどうすればよいですか?
問題があるかどうかはわかりませんが、Qtでこれを行っています。
私だったら、次のように書きます。
#include <QString>
#include <QSpinBox>
#include <QList>
#include <QLabel>
...
void ConfirmationPage::displaySpinBoxNameValues()
{
QString myText;
// Get the spinboxes from your tab.
// Use pointer anywhere here if you use that
foreach (SpinBox spinbBox, SpinBoxList) {
if (spinBox.value() > 0) {
myText.append(QString("Name: ") + spinBox.text());
myText.append(QString("\tValue: ") + spinBox.value());
myText.append('\n');
}
}
if (myText.isEmpty())
myText.append("No QSpinBox has value greater than zero!\n");
// Could be a QLabel, etc.
myDisplayWidget.setText(myText);
}
...
これに使用されるメソッドを理解するには、次のメソッド ドキュメントが必要です。
スピンボックスのリストを取得して、次のように反復できます。
QList<QSpinBox *> list = this->findChildren<QSpinBox *>();
foreach(QSpinBox *spin, list)
{
if(spin->value()>0)
{
QDebug()<< spin->objectName();
}
}
objectName()
以前に によってスピンボックスに名前を割り当てている場合は、 によってオブジェクトの名前を取得できますsetObjectName(const QString &name)
。