Results 1 to 3 of 3

Thread: Objects between QT Gui and another QT Thread

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Objects between QT Gui and another QT Thread

    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!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Objects between QT Gui and another QT Thread

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Objects between QT Gui and another QT Thread

    Thanks for the reply, amleto!
    I was suspecting that, but my experience envolving thread is close to none.

Similar Threads

  1. Number of objects in thread?
    By iraytrace in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2011, 23:13
  2. Replies: 3
    Last Post: 9th January 2010, 16:47
  3. Replies: 9
    Last Post: 28th November 2009, 21:31
  4. Replies: 16
    Last Post: 7th October 2009, 09:17
  5. Replies: 7
    Last Post: 18th July 2006, 22:33

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.