multithreading - How can I use multi thread in Qt/c++ to access my data base with an Api? -


i have problem, i'm connecting program data base api, use network , webkit webkitwidgets funtions in qt. have been able without problem.

the think it's have call funtions in api class different threads.

firts try passing api object qthread class, i'm getting error:

@qobject: cannot create children parent in different thread. (parent serialport(0x24a1738), parent's thread qthread(0x24a1770), current thread qthread(0x18a8b0) 

so try ussing signals ans slots, work firts function use, funtion create call in data base log, when try close log, can send information needed. error:

 qeventloop::exec: instance xxxxxx has called exec() 

what best way work threads avoid problems ??

you haven't provided code, error messages. since have guess, i'll you're creating qobject-derived worker object , using qobject::movetothread method change thread affinity. problem in case you've given worker object parent. can't use movetothread on object has parent. so, don't set parent of worker object when create , should good-to-go.

as others users have commented, need use signals & slots initiate queries, etc. in worker object. qt handle synchronization issues via thread's event loop, don't have worry mutex locking, etc (as long use sig/slot invoke methods , output values worker object).

don't forget call qthread::start thread's event loop started.

note 1: assume you're using recent version of qt (>= 4.8).

note 2: if you're using qsqldatabase , friends access db, make sure create db connection in worker object after moved new thread.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -