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. QComboBox Foreign Key
QtWS25 Last Chance

QComboBox Foreign Key

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k Views
  • 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.
  • T Offline
    T Offline
    Tikani
    wrote on last edited by
    #1

    Good day!
    In my application I work with SQLite3 database where 3 tables are stored. One of these table has a foreign key constraints and refers to other 2 tables:

    CREATE TABLE munits
    (
        id INTEGER PRIMARY KEY NOT NULL,
        munit TEXT NOT NULL UNIQUE
    )
    
    CREATE TABLE ctypes
    (
        id INTEGER PRIMARY KEY NOT NULL,
        ctype TEXT NOT NULL UNIQUE
    )
    
    CREATE TABLE sa_kinds
    (
        id INTEGER PRIMARY KEY NOT NULL,
        sa_kind TEXT NOT NULL UNIQUE,
        munit_id  INTEGER NOT NULL,
        ctype_id INTEGER NOT NULL
        FOREIGN KEY(munit_id) REFERENCES munit(id),
        FOREIGN KEY(ctype_id) REFERENCES ctype(id)
    ) 
    

    Tables ctypes and munits are linked with QSqlTableModel, sa_kinds - with QRelationalTableModel.
    Each table is binded with a separate QTableView, but I edit data not in the cells directly - I wrote a separate modal dialog with QLineEdits and QComboBoxes.

    What I want to achieve:

    • Human-readable values in the parent sa_kinds table instead of id codes when it is displayed in QTableView
    • When I edit sa_kinds table's data in the modal dialog, I want QComboBoxes to show human-readable values from munits and ctypes tables in a drop-down lists but, after clicking OK, to update row with corresponding id codes

    Thanks in advance.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tikani
      wrote on last edited by
      #2

      Can anybody help?

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

        Hi,

        You can set your table model on the combo box so you can choose the text you want and based on that you can retrieve the id you are looking for.

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

        T 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          You can set your table model on the combo box so you can choose the text you want and based on that you can retrieve the id you are looking for.

          T Offline
          T Offline
          Tikani
          wrote on last edited by
          #4

          @SGaist
          Ok! Huge thanks!

          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