I can´t see DB querys in a tableView or ListView
-
When i asign a query to a TableView or a ListView i cant see the text. I know that the information is there because i can select the same number of items, but these doesn´t have text. My DB has a mdb format.
This is the code that i use:
@if (db.open()) {
QSqlQueryModel * model = new QSqlQueryModel(); QSqlQuery* query = new QSqlQuery(db); query->prepare("Select * From Clientes"); query->exec(); model->setQuery(*query); ui->tableView->setModel(model);@
Why can i do to visualize the text of the query?
For more information here you have the value of the query:
@qDebug()<< query->value(0);
QVariant(int, 1)qDebug()<< (model->record(0));
" 0:" QSqlField("Id", int, length: 10, required: yes, generated: yes, typeID: 4) "1"
" 1:" QSqlField("Nombre", QString, length: 255, required: no, generated: yes) "Miguel"
" 2:" QSqlField("Apellidos", QString, length: 255, required: no, generated: yes) "Garcia Hernandez"4
@Sorrry for my english and thank you!
-
Hi and welcome to devnet,
@
model->setQuery(*query); << don't do this, there's no need to allocate a QSqlQuery on the heap
@Try:
@
model->setQuery("SELECT * FROM Clientes", db);
@ -
Did you check whether you had any error returned by QSqlQueryModel::lastError ?