QTableView displays column heading incorrectly when displaying results of a SQL query?
-
wrote on 13 Mar 2011, 12:57 last edited by
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.
-
wrote on 13 Mar 2011, 13:44 last edited by
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");@
-
wrote on 13 Mar 2011, 14:02 last edited by
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.
-
wrote on 13 Mar 2011, 15:53 last edited by
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
-
wrote on 13 Mar 2011, 16:03 last edited by
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.
-
wrote on 13 Mar 2011, 17:23 last edited by
I've raised fault report "QTBUG-18095":http://bugreports.qt.nokia.com/browse/QTBUG-18095
Edit: fixed link; Andre
1/6