Ieshir
17th September 2014, 19:38
Hello.
1)I have a class (doesn't work with gui), where I have slot for connect to the database(PSQL)
MyClass * cl = new MyClass;
2)next i create new thread
QThread * thread = new QThread;
myclass->moveToThread(thread);
thread->start();
..
emit connectToDB();
...
3)next make query in gui-class or myclass;
QSqlQuery query;
query.prepare("text here");
query.exec(); //
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?
1)I have a class (doesn't work with gui), where I have slot for connect to the database(PSQL)
MyClass * cl = new MyClass;
2)next i create new thread
QThread * thread = new QThread;
myclass->moveToThread(thread);
thread->start();
..
emit connectToDB();
...
3)next make query in gui-class or myclass;
QSqlQuery query;
query.prepare("text here");
query.exec(); //
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?