Results 1 to 2 of 2

Thread: QThread and QSqlDatabase

  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QThread and QSqlDatabase

    Hi All,

    Regarding connections to a PostgreSQL outside a QThread Object...

    Current setup:
    The connection to the database is created in the main who in turn fires QThread objects to handle incoming socket connections and update the DB's tables with their data...

    I *seem* to remember that there was a problem creating connections to a DB outside of a QThread Object and then executing queries inside the thread... is this true?

    My point being the application seg-faulting every once in a while with no reproducible pattern...

    Must I create a new connection to the DB for every new thread? I mean... it makes sense that once the connection is created the queries will use the app's default db object...

    Already thankful for any insight,
    Pedro Doria Meunier

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: QThread and QSqlDatabase

    UPDATE:

    Never mind. I've solved it.
    It turns out that you cant have a shared DB connection throughout your threads.
    One needs to:
    a) have a unique connection to the DB on each thread
    b) have a unique connection name for each thread
    c) remember to close() the connection.

Similar Threads

  1. SQL QThread how i can insert a lock?
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th June 2007, 00:12

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.