質問

So, I have an extensive list of spinboxes (30) in one tab and a confirmation page on another tab. How can I can display only the names and values of those above 0 in the confirmation page?

Not sure if it matters, I'm doing this in Qt.

役に立ちましたか?

解決

If I were you, I would be writing something like this:

confirmationpage.cpp

#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);
}
...

You would need the following method documentations to understand the methods used for this:

QLabel text property

QLabel value property

他のヒント

You can obtain the list of spinboxes and iterate over them like:

QList<QSpinBox *> list = this->findChildren<QSpinBox *>();

foreach(QSpinBox *spin, list)
{
    if(spin->value()>0)
    {
        QDebug()<< spin->objectName();
    }
}

You can get the name of the object by objectName() if you have previously assigned names to your spinboxes by setObjectName(const QString &name) .

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top