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. QTableView displays column heading incorrectly when displaying results of a SQL query?
Forum Updated to NodeBB v4.3 + New Features

QTableView displays column heading incorrectly when displaying results of a SQL query?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.8k 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.
  • J Offline
    J Offline
    Jonathan
    wrote on last edited by
    #1

    Here is some reconstructed code (ie not independantly tested):

    @QSqlQueryModel *model = new QSqlQueryModel;
    model->setQuery("SELECT type, COUNT(titles.title) FROM titles GROUP BY type");
    QTableView view = new QTableView;
    view->setModel(tableModel);
    mainLayout->addWidget(view);
    show();@

    The code queries a table "titles" which contains a list of book titles and their types (business, cooking, sport, etc) plus other stuff.

    The column headings display correctly apart from that for
    @COUNT(titles.title)@
    which displays as
    @title)@

    However if instead I have @COUNT(title)@ the column heading displays correctly, ie as
    @COUNT(title)@

    Possibly related to this problem: "titles.type" displays as "type".

    This all becomes a big issue when attempting to correctly display the headings for the results of a join.

    Thinking about it, this may be an HTML related problem, ie the view thinks it should be parsing HTML in the heading.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Have you tried modifying your query to us an AS clause? ie something like this:

      @model->setQuery("SELECT type, COUNT(titles.title) AS 'Title Count' FROM titles GROUP BY type");@

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        I agree with ZapB (Sean). Did you check what the column title for that query is if you run it through your DB directly? What DB are you using?

        AFAIK, most Qt SQL drivers won't just make up names for columns themselves. Instead, they get them from the database engine they interact with. There may be a bug in that interaction, of course, but you should try to determine the source of that problem.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jonathan
          wrote on last edited by
          #4

          Using

          @model->setQuery("SELECT type, COUNT(titles.title) AS 'Title Count' FROM titles GROUP BY type");@

          displays the correct heading. However surely both options should work?

          I'm using SQLite from Qt4.7.2

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            It would take more debugging & analysis to see where the problem lies. I would not automatically conclude the problem is with Qt, though it is possible that the SQL driver for SQLite is at fault, of course.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jonathan
              wrote on last edited by
              #6

              I've raised fault report "QTBUG-18095":http://bugreports.qt.nokia.com/browse/QTBUG-18095

              Edit: fixed link; Andre

              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