Results 1 to 2 of 2

Thread: How to display result sets of 2 tables in SQL using setQuery?

  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question How to display result sets of 2 tables in SQL using setQuery?

    The code below can only display result sets of 1 of the table(TABLE1 in MYSQL):
    Qt Code:
    1. model->setQuery("SELECT field1,field2,field3 FROM TABLE1");
    2. model->setHeaderData(0, Qt::Horizontal, QObject::tr("Field 1"));
    3. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Field 2"));
    4. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Field 3"));
    5.  
    6. if(model->lastError().isValid())
    7. qDebug() << model->lastError();
    8.  
    9. QTableView *view = new QTableView;
    10. view->setModel(model);
    11. view->show();
    To copy to clipboard, switch view to plain text mode 

    How to display result sets of 2 tables(TABLE1 and TABLE2 in MYSQL) in one data model?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display result sets of 2 tables in SQL using setQuery?

    "SELECT t1.field1, t1.field2, t2.field1, t2.field2 from table1 t1 JOIN table2 t2 ON <join condition goes here>"
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    babygal (20th September 2010)

Similar Threads

  1. Replies: 4
    Last Post: 17th September 2010, 20:18
  2. Replies: 4
    Last Post: 13th July 2010, 05:17
  3. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 08:39
  4. Replies: 1
    Last Post: 16th May 2010, 19:25
  5. Replies: 8
    Last Post: 8th May 2009, 09:14

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.