Results 1 to 5 of 5

Thread: QSqlRelationalTableModel query question

  1. #1
    Join Date
    Jan 2008
    Posts
    58
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QSqlRelationalTableModel query question

    Hi,

    I'm currently busy with a SQLite database, and I have a question.

    I have two tables, clients and orders, the orders table has to be populated in the QSqlRelationalTableModel. But the client information has to be added to the row.

    So the first thing I did was is setRelation(clientId, "cid", "First Name"); (with clientId as columnIndex from the orders table) and it works, but I need more client information than the first name.

    How can I solve such a problem?

    Kind regards,

    Marcel Boersma

  2. #2
    Join Date
    Jan 2008
    Posts
    58
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QSqlRelationalTableModel query question

    I've found a solution, right now I'm using a QSqlQueryModel so I can combine some queries.

    But now I have another problem(A)

    Some code snippets:

    Qt Code:
    1. mainWindow::mainWindow(QWidget *parent){
    2. //create model
    3. QSqlQueryModel *orderModel = new QSqlQueryModel;
    4.  
    5. //setQueryCritics
    6. this->setQueryCritics(orderModel, 1);
    7. }
    8.  
    9. void mainWindow::setQueryCritics(QSqlQueryModel &model, int type)
    10. {
    11.  
    12. QSqlQuery query;
    13. query.prepare("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.oid = c.cid and o.currentStatus = :status ");
    14.  
    15. switch(type){
    16. case 1 :
    17. //orderModel
    18. query.bindValue(":status", "1");
    19. break;
    20. case 2 :
    21. //finishModel
    22. query.bindValue(":status", "2");
    23. break;
    24. case 3 :
    25. //trashModel
    26. query.bindValue(":status", "3");
    27. break;
    28. case 4 :
    29. //clientModel
    30. query.prepare("SELECT * FROM clients");
    31. break;
    32. }
    33.  
    34. model.setQuery(query);
    35.  
    36.  
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 

    and here is the error message I get:
    mainWindow.cpp:37: error: no matching function for call to 'mainWindow::setQueryCritics(QSqlQueryModel*&, int)'
    I hope and I think it's a real simple problem, but I don't see the solution
    Can somebody help me with this?

    Kind regards,

    Cyberboy

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSqlRelationalTableModel query question

    Your function takes a reference but you try to pass a pointer.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2008
    Posts
    58
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QSqlRelationalTableModel query question

    all-right, how can I edit the query of the model I pass in the function?
    Do I have to pass a pointer or a reference?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSqlRelationalTableModel query question

    Well, this is a basic C++ issue, but let's say that you might want to alter the function to take a pointer...
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    cyberboy (6th February 2008)

Similar Threads

  1. templates / Q_OBJECT question
    By _borker_ in forum Qt Programming
    Replies: 6
    Last Post: 19th December 2007, 20:35
  2. Mysql query question
    By twells55555 in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2007, 23:41
  3. Aborting a query set on a TableModel
    By Quid in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2006, 22:36
  4. combining query lists
    By jayw710 in forum Qt Programming
    Replies: 4
    Last Post: 10th February 2006, 21:17

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.