Results 1 to 5 of 5

Thread: SQL query

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL query

    I had assumed that something along the lines of

    Qt Code:
    1. QSqlQueryModel *model = new QSqlQueryModel(this);
    2. QSqlQuery query;
    3. query.prepare("INSERT INTO INSERT INTO people(ID,Name,Age) VALUES (?, ?, ?)");
    4. query.addBindValue(1);
    5. query.addBindValue("Fred Bloggs");
    6. query.addBindValue(21);
    7. model->setQuery(query);
    To copy to clipboard, switch view to plain text mode 

    would do the trick but 'query.lastQuery()' seems to indicate that the values are not being bound.

  2. #2
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL query

    Thanks montuno,

    I'll try the the QSqlTableModel you suggest.

  3. #3
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL query

    Actually I've discovered that the following works!

    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("INSERT INTO INSERT INTO people(ID,Name,Age) VALUES (?, ?, ?)");
    3. query.addBindValue(1);
    4. query.addBindValue("Fred Bloggs");
    5. query.addBindValue(21);
    6. query.exec();
    7. model->setQuery("SELECT * FROM clients ORDER BY clientName");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. SQL slow query - table update
    By lasher in forum Newbie
    Replies: 4
    Last Post: 21st October 2009, 23:12
  2. problem while executing SQL query
    By sosanjay in forum Qt Programming
    Replies: 3
    Last Post: 9th October 2009, 12:52
  3. Best way to abort long SQL query?
    By wdezell in forum Newbie
    Replies: 1
    Last Post: 11th September 2009, 22:05
  4. SQL query - navigation buttons
    By apffal in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2009, 08:38
  5. QTableWidget Sql Query 25.000 records
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2008, 14:54

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
  •  
Qt is a trademark of The Qt Company.