PDA

View Full Version : Edit QTableView cell fields



Bruschetta
30th September 2016, 09:46
Hello,
i'm trying to edit a table cell of my QTablView but with no luck.
The code of the function i'm calling to populate it is:



void perito::on_pushButton_listaP_clicked()
{
Conn conn;
QSqlQueryModel *modal = new QSqlQueryModel();
conn.connectionOpen();
QSqlQuery *qry = new QSqlQuery(conn.mydb);
qry->prepare("SELECT * FROM perito");
qry->exec();
modal->setQuery(*qry);
ui->tableView->setModel(modal);
conn.connectionClose();
}


The table is well populated but i'm unable to modify any cell. I have made the table with designer but the field "NoEditTriggers" is unchecked ..

Any hints? Thanks for your time and answers

anda_skoa
30th September 2016, 11:44
From the documenation of QSqlQueryModel:


The QSqlQueryModel class provides a read-only data model for SQL result sets.


Cheers,
_

P.S.: you are leaking the QSqlQuery object

Bruschetta
30th September 2016, 13:52
Thanks a lot anda_skoa, i solved my problem!

d_stranz
30th September 2016, 15:23
P.S.: you are leaking the QSqlQuery object

As well as the QSqlQueryModel. Each time you click the button, it creates each of these objects, and they never get deleted. Setting a new model on the table view does not delete the old model, it just hangs around until your program finally exits and the OS cleans up. Create the model instance as a child of "perito" and reuse it as needed for new queries. As a child of the perito instance, it will be deleted when perito is.