Results 1 to 4 of 4

Thread: Qt and Database connection best option

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt and Database connection best option

    Hello all!

    Whats is the best solution for database connections using Qt, open the connection when the program starts and close it when the program closes or open and close it every time it is needed?

    Thanks a lot.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Qt and Database connection best option

    The answer of course is... it depends. There is more overhead opening and closing a database continuously, but if your app only accesses the database once a day or otherwise infrequently, then opening/access/closing would be an acceptable approach.

    If you decide to leave the database open for the duration of your program's execution, make sure you commit or rollback transactions as appropriate and QSqlQuery::finish() any prepare statements you may use, as well as QSqlQuery::finish() any queries where you have only read some of the result set. i.e. You should try not to do anything that holds a lock on the database or its tables for a long period of time, etc.

    Hope that helps.

    Edit: Other considerations are the DB engine, the platform, etc. You didn't state what DB engine you're using, whether the database is accessed via the network or local disk file on your computer, etc.
    Last edited by jefftee; 19th February 2015 at 00:45.

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt and Database connection best option

    Thanks jthomps, you help me a lot.

    I am using firebird database locally in OsX Windows 7 and 8.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and Database connection best option

    Depends on what application is using the database. Write some more.

Similar Threads

  1. database connection
    By mak_user in forum Newbie
    Replies: 1
    Last Post: 9th February 2011, 10:23
  2. Connection With database
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2010, 10:18
  3. Database connection
    By poporacer in forum Newbie
    Replies: 7
    Last Post: 7th September 2010, 08:49
  4. cannot share the database connection!!!!
    By cbarmpar in forum Qt Programming
    Replies: 13
    Last Post: 23rd September 2008, 15:42
  5. database connection
    By peace_comp in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 13:16

Tags for this Thread

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.