Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

sqlite: QTreeView + QSqlTableModel



  • Hi!
    I have two tables in DB. There is 'one to multiple' connection.
    I need to:

    1. Show the main table.
    2. Show the second table by row selection of the main table.
    3. Needs to customization of the main table header: QLineEdit for each columns for filtering.
    //Table1
        model1 = new QSqlTableModel(this);
        model1->setTable("table1_t");
        model1->setEditStrategy(QSqlTableModel::OnManualSubmit);
        model1->select();
    
        model1->setHeaderData(0, Qt::Horizontal, tr("Col1"));
        model1->setHeaderData(1, Qt::Horizontal, tr("Col2"));
    
        ui->view1->setModel(model1);
    
        //Table2
        model2 = new QSqlTableModel(this);
        model2->setTable("table2_t");
        model2->select();
    
        model2->setHeaderData(0, Qt::Horizontal, tr("Col1"));
        model2->setHeaderData(1, Qt::Horizontal, tr("Col2"));
        model2->setHeaderData(2, Qt::Horizontal, tr("Col3"));
    
        ui->view2->setModel(model2);
    

    How to connect view1 and view2 between each other?
    Thank you!


  • Qt Champions 2019

    @sitesv said in sqlite: QTreeView + QSqlTableModel:

    How to connect view1 and view2 between each other?

    See the selectionChanged() signal


Log in to reply