I'm using this code to query sqlite and put the results in a QTableView.
//MainWindow.cpp
void MainWindow::on_pushButton_clicked()
{
    QSqlQueryModel * modal=new QSqlQueryModel();
    connOpen();
    QSqlQuery* qry=new QSqlQuery(mydb);
    qry->prepare("select * from database");
    qry->exec();
    modal->setQuery(*qry);
    //from stack
    modal->insertColumn(0);
    ui->tableView->setModel(modal);
    //from stack
    ui->tableView->resizeColumnsToContents();
    int p;
    for(p=0; p<modal->rowCount(); p++)
    {
        ui->tableView->setIndexWidget(modal->index(p,0),new QCheckBox());
    }
    connClose();
    qDebug() <<(modal->rowCount());
}
I've seen several examples of the web for adding checkboxes to a column, but I'm not quite sure what to use for my simple example.
- This answer suggests a few lines that doesn't seem standard.
 - There are more examples like this and this one that appear to outline what I need, but it's unclear to where you place the code.
 
What I intend to do is to have column 1 checkable. On next btn press, If checked those rows of data get written to a file.
I still need to understand how to loop thru the selected data, or perhaps I need to get the ids of the checked rows and do another query.
Questions:
- How do you add 1 column of editable checkboxes to QTableView?
 - How do you loop through values in the QTableView data, so values of the checked rows can be accessed?
 - How do you check all/none?