QSqlRelationalDelegate and QSqlRelationalTableModel::setRelation Bug ?



  • I have the tblCountry and the tblPort. Every port is on one country connected by IDCountry.
    Now I want show and edit the country of every port in a tableview.

      Ports.setTable("tblPort");
        Ports.setRelation(3, QSqlRelation(tblCountry, fieldID, fieldDesc));
        ui->PortsTV->setModel(&Ports);
        ui->PortsTV->setItemDelegateForColumn(3,
            new QSqlRelationalDelegate(ui->PortsTV));
    

    The setRelation works. I see instead of the foreign key the country name.
    Editing works too: I get a dropdown-listbox with all countrys. Changing works. Is see the new country-text in the field in form of a dropbox entry
    BUT: when I select an other row the dropbox dissapear (thats correct) and I should see the text configured by setRelation. BUT I see then the primary key.
    So it seem after editing the setRealation has been switched off. Refreshing the grid show again the text and not the primary key.
    I cannot figure out whats wrong.



  • Bug or Feature ?

    I found out, that the realation works only OnManualSubmit correct
    Ports.setEditStrategy(QSqlTableModel::OnManualSubmit);
    In all other case I see the PrimaryKey after editing.
    Makes this sense ?


  • Lifetime Qt Champion

    Hi,

    Sounds a bit fishy, especially if it's not written in the documentation



  • @SGaist
    And very tricky is that the setRelation changes the name of the column.
    I stays not by its original name in the database (ForeignKey) but gets some extensions, so that searching column by name does not work anymore.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.