Results 1 to 2 of 2

Thread: How is a QSqlQuery bound to a QSqlDatabase?

  1. #1
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How is a QSqlQuery bound to a QSqlDatabase?

    There doesn't seem to be any part that says "this QSqlQuery operates on this QSqlDatabase".

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How is a QSqlQuery bound to a QSqlDatabase?

    There are variations on how you can do this, but the basics are:

    1. define database
    2. define query

    Sqlite example:

    Qt Code:
    1. // define database
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", <yourConnectionName>);
    3. db.setDatabaseName(dbName + ".sqlite");
    4. db.open();
    5.  
    6. // define query
    7. QSqlQuery query(db); // db ties the query to the defined, open database
    8. query.exec("SELECT * from yourTable");
    To copy to clipboard, switch view to plain text mode 

    If you split this code into two pieces then you can use the connectionName and don't have to re-define the database for each query.

Similar Threads

  1. Replies: 14
    Last Post: 16th May 2017, 03:51
  2. QSQLDatabase
    By hoshy in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2009, 15:09
  3. QThread and QSqlDatabase
    By pdoria in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2008, 03:25
  4. QSqlDatabase
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 17:53
  5. QSqlDatabase
    By raphaelf in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2006, 15:15

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.