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. QtSql Dataaware cells/boxes

QtSql Dataaware cells/boxes

Scheduled Pinned Locked Moved Unsolved General and Desktop
sql
6 Posts 2 Posters 2.1k 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.
  • G4banditG Offline
    G4banditG Offline
    G4bandit
    wrote on last edited by G4bandit
    #1

    I find the examples very helpful from Qt regarding Sql possibilities given by Qt. Thanks on this place.

    Here is one of this examples:
    0_1515765773402_ea21ad47-ae85-400c-b3e8-8faa5a42cca9-grafik.png

    When I click inside a box of the row "Genre" or "Author Name" than a dropdown appears like you can see on the picture, - highlighted with red frame.
    BUT
    This functionality is only given because it is used QSqlRelationalTableModel and with the function "setRelation" a relation is set to this columns "Genre" and "Author Name".

    MY QUESTION
    Is there a comfortable possibility given to do the same stuff only without QSqlRelationalTableModel?
    Means there is a table like this

    0_1515766154374_160a4228-70f8-4b80-afe3-2da98711626b-grafik.png
    Only such table without any relations to other tables. And it should not be the aim to create related tables.

    Now when I decide to change from ProcessMGA the Atribute "HasToDoWith" I would like to get the dropdown list where I can EITHER select from already existing values inside the attribute "HasToDoWith" OR just write a new one like "Banana".

    1 Reply Last reply
    0
    • G4banditG Offline
      G4banditG Offline
      G4bandit
      wrote on last edited by
      #2

      I found newly this possibility

      ui->QComboBox1->setModel(QSqlTblModel);

      But well that is a ComboBox and not something inside the TableView.
      But here I also need to find out how to say which attribute of the QSqlTblModel shall be taken inside the dropdown list of the combobox.

      mrjjM 1 Reply Last reply
      0
      • G4banditG G4bandit

        I found newly this possibility

        ui->QComboBox1->setModel(QSqlTblModel);

        But well that is a ComboBox and not something inside the TableView.
        But here I also need to find out how to say which attribute of the QSqlTblModel shall be taken inside the dropdown list of the combobox.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @G4bandit

        • need to find out how to say which attribute of the QSqlTblModel shall be taken inside the dropdown

        Hi
        Sounds to me you are looking for
        http://doc.qt.io/qt-5/qcombobox.html#modelColumn-prop
        (to select what column that is used in combobox)

        1 Reply Last reply
        2
        • G4banditG Offline
          G4banditG Offline
          G4bandit
          wrote on last edited by
          #4

          @mrjj

          My code looks like this

          TblModel = new QSqlTableModel(this);
          TblModel->setTable("Tbl1");
          TblModel->select();
          
             ui->QComboBox1->setModelColumn(TblModel->fieldIndex("Attribute1"));
          
          

          So the result is, although Attribute1 is filled with data, that the data will not appear in the dropdown of QComboBox.
          No errors no warnings when compiling.

          mrjjM 1 Reply Last reply
          0
          • G4banditG G4bandit

            @mrjj

            My code looks like this

            TblModel = new QSqlTableModel(this);
            TblModel->setTable("Tbl1");
            TblModel->select();
            
               ui->QComboBox1->setModelColumn(TblModel->fieldIndex("Attribute1"));
            
            

            So the result is, although Attribute1 is filled with data, that the data will not appear in the dropdown of QComboBox.
            No errors no warnings when compiling.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Are you sure fieldIndex and setModelColumn have the same idea about column numbering ?
            Check the values.

            1 Reply Last reply
            0
            • G4banditG Offline
              G4banditG Offline
              G4bandit
              wrote on last edited by
              #6

              @mrjj

              Hey I got it !!! I am gutting better :) unbelivable I solved it this way:

                 ui->CB_AdaNr->setModel(TblModel);
                 ui->CB_AdaNr->setModelColumn(TblModel->fieldIndex("Attribute1"));
              

              And it works.

              Still have the issue that I would like to have dropdowns inside of the QTableView, - the topic at the top.

              1 Reply Last reply
              1

              • Login

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