Bugsia
Bugsia

Reputation: 25

Qt: QFormLayout::addRow(QWidget* label, QWidget* field) not adding a new row

I am trying to add a new row to my QFormLayout after I have loaded two QLineEdits from a file, which works, but when I run my code it doesnt add anything, ot atleast anything that I can see. And I am also not able to add any wigets using QLayout::addWidget(QWidget* widget) anymore, which I used to be able to.

Thanks

The code, where it doesnt work:

void Kegelbuch::load(QString path, QString tab) {
    //Load json file
    Datastream* loadStream = new Datastream;
    QJsonObject data = loadStream->loadData(path);

    //Declaring all important Variables
    QJsonArray keglerFullName;
    QJsonArray keglerShortName;
    QFormLayout* formLayout = (QFormLayout*)ui.keglerTab->layout();
    int defaultRows = 2, width = 155;

    //Retriev arrays from file
    if (data.contains("KeglerFullName") && data["KeglerFullName"].isArray()) {
        keglerFullName = data["KeglerFullName"].toArray();
    }
    if (data.contains("KeglerShortName") && data["KeglerShortName"].isArray()) {
        keglerShortName = data["KeglerShortName"].toArray();
    }

    //Correctly add QLineEdits to the FormLayout
    for (auto names : boost::combine(keglerFullName, keglerShortName))  {
        QLineEdit fullNameEdit;
        QLineEdit shortNameEdit;
        QJsonValue fullNameValue, shortNameValue;

        boost::tie(fullNameValue, shortNameValue) = names;
        
        if (fullNameValue.isString()) {
            fullNameEdit.setText(fullNameValue.toString());
            fullNameEdit.setObjectName("fullName");
            fullNameEdit.setMinimumWidth(width);
        }
        if (shortNameValue.isString()) {
            shortNameEdit.setText(shortNameValue.toString());
            shortNameEdit.setMaximumWidth(width);
            shortNameEdit.setObjectName("shortName");
        }

        /*
        if (keglerFullName.at(1).isString()) {
            fullNameEdit->setText(keglerFullName.at(1).toString());
            fullNameEdit->setObjectName("fullName");
            fullNameEdit->setMinimumWidth(width);
        }
        if (keglerShortName.at(1).isString()) {
            shortNameEdit->setText(keglerShortName.at(1).toString());
            shortNameEdit->setMaximumWidth(width);
            shortNameEdit->setObjectName("shortName");
        }
        */

        formLayout->addRow(&fullNameEdit, &shortNameEdit);
    }
}

Upvotes: 0

Views: 252

Answers (0)

Related Questions