04-04-2013 12:51 AM
I am doing multithread in my app. In my new thread I use two signal and two slot.
Task of 1st signal & slot -
Given an object parameter in the signal I invoke a member function of this class in the slot.
Task of 2nd signal & slot -
Given the same object parameter to delete this object.
You can arise a quesiton why I am deleting memory in this way. Actually in my new thread using 1st signal & slot I want to download map tile from server. But in QT framework I didn't able to download map tile from my new thread. So, I use MoveToThread() to move my object of new thread to the main thread and let the main thread do it for me. But now when I want to free my memory I can't delete it from my new thread because main thread is working with it. So I introduse 2nd signal slot mechanism to free my memory.
All the thing is working well and good except, when I pan my map continuously & quickly it got crashed. Because my 1st signal & slot working with already deleted object by 2nd signal & slot.
Hopefully I make you all understand the situation, if you need further clarification please let me know. It's a very critical issue for me. Hopyfully you guys can help me.
Solved! Go to Solution.
04-04-2013 02:37 AM
I have a similar scenario in my application, whereby I use another thread to load data for my main thread to use. This is the approach that I took:
Main thread invokes, loader thread;
Loader thread creates data objects, loads data into them, and then passes them to main thread via a signal. (not forgetting to use MoveToThread() before emitting the signal).
Main thread receives the objects via a slot, and then stores and uses the data objects.
Main thread deletes data objects at the appropriate time.
I think if you simplify what you are trying to do, you will get a better result. I would guess that your main thread knows when it is time to delete the objects, so it may as well manage (delete) them itself.