2

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.

Nejat
  • 31,784
  • 12
  • 106
  • 138
  • Can not you just check the value of each spin box using `getValue()` and then display name/value when value>0? If you have used a list/vector to store the spinboxes then you can do it in a loop. – Rakib May 02 '14 at 20:40
  • @RakibulHasan: this is not java or C. There is no getValue(). – László Papp May 03 '14 at 07:39

2 Answers2

1

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

László Papp
  • 51,870
  • 39
  • 111
  • 135
0

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) .

Nejat
  • 31,784
  • 12
  • 106
  • 138