QtSql Dataaware cells/boxes



  • 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".



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


  • Qt Champions 2017

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



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


  • Qt Champions 2017

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



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


Log in to reply
 

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