Results 1 to 7 of 7

Thread: SQL module and Thread-safe

  1. #1
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default SQL module and Thread-safe

    I have database object in my mainthread (GUI).

    I must do a lot of insert statement so I want to do this in other thread.
    Can I create QSqlQuery in other(not main) thread and execute a lot of inserts?
    QSqlQuery use database object which is created in main thread.
    In QT doc is write that qt database object should not be used in other thread, so how can I start transaction in other thread?


    I cant create second connection object in second thread because I use firebird embedded database.


    sory for my poor english

  2. #2
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: SQL module and Thread-safe

    I'am interessted in this too.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: SQL module and Thread-safe

    http://doc.qt.nokia.com/4.6/threads-...the-sql-module

    You can use the sql module in a different thread than your main GUI thread.
    BUT!!! You have to keep everything in one thread. You can not create the database in thread 1 and do a query in thread 2.

  4. #4
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SQL module and Thread-safe

    so when I use firebird embedded I cant write mutlithread program.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: SQL module and Thread-safe

    Multithreaded program: yes (you can have a database manager in a separate thread)
    Using multiple threads for the sql classes: no

    There's no reason to do that either since most databases are optimized to work in a certain way.

    If you want to add lots of data at the same time in a database, don't do this query by query. Start a transaction, fill the transaction buffer and then commit it in one go.

  6. #6
    Join Date
    Mar 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SQL module and Thread-safe

    Firebird team release 2.5RC3 version.
    In release note we can read:

    "The client libraries, including the embedded one, can now be used in multi-threaded applications without any application-level synchronization."

    so with this library can I use Qt sql classes (with one connection) in more than one thread?

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: SQL module and Thread-safe

    No.

    This has nothing to do with the used database, but everything with Qt.

Similar Threads

  1. thread-safe
    By babymonsta in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2010, 10:18
  2. Why is QMutex Thread Safe?
    By Kind Lad in forum Newbie
    Replies: 3
    Last Post: 22nd February 2010, 04:46
  3. About the QSound,is thread safe?
    By cspp in forum Qt Programming
    Replies: 0
    Last Post: 6th November 2009, 14:26
  4. Is a QProcess thread safe in Qt4?
    By Jay_D in forum Qt Programming
    Replies: 4
    Last Post: 1st September 2009, 16:38
  5. What makes something not thread safe?
    By tgreaves in forum Newbie
    Replies: 9
    Last Post: 20th February 2009, 20:16

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.