Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Empty qsqlrelationaltablemodel



  • When I put model->select(); after relations, the model is empty, when I put it back before relations, the table displays correctly, but when I edit any cell the whole row becomes empty and gets "!" on the left. No errors.

    QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this, db1);
    model->setTable("syllabi");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    model->setRelation(3, QSqlRelation("activity_types", "activity_type_id", "activity_type_name"));
    model->setRelation(0, QSqlRelation("teachers", "teacher_id", "teacher_name"));
    //model->select();
    qDebug() << model->lastError();
    
    ui->tableView->setModel(model);
    ui->tableView->setItemDelegate(new QSqlRelationalDelegate(ui->tableView));
    ui->tableView->horizontalHeader()->setStretchLastSection(true);
    ui->tableView->setColumnHidden(9, true);

Log in to reply