Results 1 to 4 of 4

Thread: QtSql and Thread

  1. #1
    Join Date
    Nov 2013
    Posts
    17
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QtSql and Thread

    Hello.
    1)I have a class (doesn't work with gui), where I have slot for connect to the database(PSQL)
    Qt Code:
    1. MyClass * cl = new MyClass;
    To copy to clipboard, switch view to plain text mode 
    2)next i create new thread
    Qt Code:
    1. QThread * thread = new QThread;
    2. myclass->moveToThread(thread);
    3. thread->start();
    4. ..
    5. emit connectToDB();
    6. ...
    To copy to clipboard, switch view to plain text mode 

    3)next make query in gui-class or myclass;
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("text here");
    3. query.exec(); //
    To copy to clipboard, switch view to plain text mode 
    4)
    Threads and the SQL Module

    A connection can only be used from within the thread that created it. Moving connections between threads or creating queries from a different thread is not supported.
    why query.exec() return true with correct data in gui-thread and another thread?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QtSql and Thread

    QSqlQuery::exec() returns true if the query executed. There is insufficient information in your post to know how and where the connection was created and thus whether this is expected, correct, or accidentally correct behaviour.

  3. #3
    Join Date
    Nov 2013
    Posts
    17
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtSql and Thread

    What other information should be submitted?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtSql and Thread

    Quote Originally Posted by Ieshir View Post
    What other information should be submitted?
    At least show us where you create database connections. If what you posted is an actual code then it is most likely invalid as the query uses the default database connection.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Building QtSql only
    By lk in forum Qt Programming
    Replies: 9
    Last Post: 18th February 2013, 14:03
  2. QtSQL - Where is My Database?
    By feuerball11 in forum Qt Programming
    Replies: 18
    Last Post: 20th July 2012, 11:02
  3. QtSQL and databse
    By prophet0 in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2011, 06:22
  4. QTSQL on ARM board
    By chaithrakr7 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 26th March 2011, 04:45
  5. QtSql or QtSql/ ?
    By szisziszilvi in forum Newbie
    Replies: 3
    Last Post: 8th March 2011, 15:44

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.