0

after creating some database applications using Qt and widgets, I am exploring Quick Controls and QML. I want to mimic the use of a QComboBox mapped to a QSqlRelationalTableModel to populate one table out of another one. Something similar to:

ui->cmbArea->setModel(model->relationModel(areaIdx));
ui->cmbArea->setModelColumn(model->relationModel(areaIdx)->fieldIndex("description"));
mapper->addMapping(ui->cmbArea, areaIdx);

(Using widgets, cmbArea is a QComboBox, model is a QSqlRelationalTableModel, and mapper a QDataWidgetMapper)

I managed to get something working like:

property ModeloCodificador modeloCodificador: ModeloCodificador{}
property ModeloTabla modeloTabla: ModeloTabla{}

ComboBox {
    model: modeloCodificador
    textRole: "elemento"
    valueRole: "id"
    Component.onCompleted: {
          currentIndex = find(modeloTabla.get(0, modeloTabla.codigoIdx), Qt.MatchExactly)
    }
    onActivated: {
          modeloTabla.set(0, modeloTabla.codigoIdx, currentValue)
    }
}

Is there a better way to accomplish this?

0 Answers0