Qt World Summit: Submit your Presentation

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");

    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!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    model->setQuery(*query); << don't do this, there's no need to allocate a QSqlQuery on the heap

    model->setQuery("SELECT * FROM Clientes", db);

  • thank you for the reply.

    I try your advice but i have the same problem.

    Maybe it doesn´t query or model error?

    thank you one more time!

  • Lifetime Qt Champion

    Did you check whether you had any error returned by QSqlQueryModel::lastError ?

  • Yes, I checked it.

    The result of this was: QSqlError(-1, "", "")


Log in to reply