Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I can´t see DB querys in a tableView or ListView
Qt 6.11 is out! See what's new in the release blog

I can´t see DB querys in a tableView or ListView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Yes, I checked it.

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

            thanks

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved