PDA

View Full Version : Objects between QT Gui and another QT Thread



renatolond
2nd August 2012, 23:19
Hello!

I'm doing a splash screen in my program, in C++, and I want that my initialization tasks be done in a thread, let's call it LoadingThread. But, in LoadingThread I would create some lists, load some settings, and etc. Things that will be used after LoadingThread is over.
My question is: what is the best way to do this? Should I create everything and then use QSharedMemory to transfer back to GUI thread? When the thread is over, will the objects created with new in LoadingThread be deleted as well, or could I simply pass the pointers back to the GUI thread? Am I complicating all this for no reason? :)

Thanks!

amleto
3rd August 2012, 00:14
you dont need sharedmemory - that is IPC iirc.

Just because a thread stops running doesn't mean all objects that were accessed in the thread die. You can use moveToThread at 'any' time.

If the things are are loading are not even QObjects (e.g data containers like QList ...), then you don't need to care what thread they are in. You should just care about encapsulation (ie it is in the correct class/owner) and that multi-threaded access is properly handled.

renatolond
3rd August 2012, 16:19
Thanks for the reply, amleto!
I was suspecting that, but my experience envolving thread is close to none. :)