PDA

View Full Version : Sqlite-using queries



malavika
20th November 2011, 13:42
i want to implement a query on my table in my code and then display it in a table view;

mayb if my query is:

select groupid,memberid from group,member where groupid=101;

if i want to imlpement this on a table how do i do it?

if i use model->setfilter(select groupid,memberid from group,member where groupid=101)
it doesn't use.
is there any other way i could do it?

b1
20th November 2011, 21:18
malavika,

You could use an QSqlQueryModel like this:



myQuery = new QSqlQueryModel;
myQuery->setHeaderData(0,Qt::Horizontal, "Column 1"); //etc as required....

myQuery->setQuery( "select groupid,memberid from group,member where groupid=101" );
tableView->setModel(myQuery);
tableView->setColumnWidth(0,145);
tableView->setColumnWidth(1,40); //etc as required.....


There are excellent examples in the Qt docs....

Also, I am not sure but I think your SQL syntax may be wrong. I understand it to be "select <fields> from <database table> where <condition>". I am not sure about the "group, member" syntax for the database table.

Hope this helps....

B1.

malavika
21st November 2011, 15:13
malavika,

You could use an QSqlQueryModel like this:



myQuery = new QSqlQueryModel;
myQuery->setHeaderData(0,Qt::Horizontal, "Column 1"); //etc as required....

myQuery->setQuery( "select groupid,memberid from group,member where groupid=101" );
tableView->setModel(myQuery);
tableView->setColumnWidth(0,145);
tableView->setColumnWidth(1,40); //etc as required.....


There are excellent examples in the Qt docs....

Also, I am not sure but I think your SQL syntax may be wrong. I understand it to be "select <fields> from <database table> where <condition>". I am not sure about the "group, member" syntax for the database table.

Hope this helps....

B1.


Thank you so much ! it worked !
thansk once again!