Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlRelationalDelegate and QSqlRelationalTableModel::setRelation Bug ?
Forum Updated to NodeBB v4.3 + New Features

QSqlRelationalDelegate and QSqlRelationalTableModel::setRelation Bug ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 999 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    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.

    1 Reply Last reply
    0
    • Andy314A Offline
      Andy314A Offline
      Andy314
      wrote on last edited by Andy314
      #2

      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 ?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Andy314A 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

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

          Andy314A Offline
          Andy314A Offline
          Andy314
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved