Results 1 to 3 of 3

Thread: Sqlite-using queries

  1. #1
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Sqlite-using queries

    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?

  2. #2
    Join Date
    Jun 2006
    Posts
    64
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sqlite-using queries

    malavika,

    You could use an QSqlQueryModel like this:

    Qt Code:
    1. myQuery = new QSqlQueryModel;
    2. myQuery->setHeaderData(0,Qt::Horizontal, "Column 1"); //etc as required....
    3.  
    4. myQuery->setQuery( "select groupid,memberid from group,member where groupid=101" );
    5. tableView->setModel(myQuery);
    6. tableView->setColumnWidth(0,145);
    7. tableView->setColumnWidth(1,40); //etc as required.....
    To copy to clipboard, switch view to plain text mode 

    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.

  3. #3
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sqlite-using queries

    Quote Originally Posted by b1 View Post
    malavika,

    You could use an QSqlQueryModel like this:

    Qt Code:
    1. myQuery = new QSqlQueryModel;
    2. myQuery->setHeaderData(0,Qt::Horizontal, "Column 1"); //etc as required....
    3.  
    4. myQuery->setQuery( "select groupid,memberid from group,member where groupid=101" );
    5. tableView->setModel(myQuery);
    6. tableView->setColumnWidth(0,145);
    7. tableView->setColumnWidth(1,40); //etc as required.....
    To copy to clipboard, switch view to plain text mode 

    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!

Similar Threads

  1. Qt Basic Queries
    By somnathbanik in forum Newbie
    Replies: 6
    Last Post: 2nd November 2010, 10:28
  2. Replies: 9
    Last Post: 19th November 2009, 09:18
  3. Using LIKE in parameterized SQL queries
    By MikeG in forum Qt Programming
    Replies: 4
    Last Post: 2nd November 2009, 19:25
  4. SQL date queries
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 10:41
  5. SQL queries and slots
    By fnmblot in forum Newbie
    Replies: 8
    Last Post: 26th April 2007, 01:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.