PDA

View Full Version : QGraphicsItem are not painted any more



dfroze
20th January 2017, 23:46
Ht all,

I am a bit new so some basic stuff i might not know. SOrry if this post should have been on the newbie section but I am not sure it s that simple.

So, I've started from example DiagramItem and added the following:
- a poolThread (producer consumer type) to update a value from each DiagramItem every 1s. More exactly, the background according to the result of a QProcess return code. After the value is changed, the item->update() is called
- a Graphics_view_zoom
- a symbol to draw in the DiagramItem when mouse hover

I am using QMutexLocker for thread safe, and no I am not using signals to communicate between the threads and the Items, just changing a value and call update().

Everything works fine at start, but after a while (couldn't find what happens), the items paint function is not called, even when i have the mouse one it. ONLY when zooming in/out does it update for a moment.
I can post section from code if needed.

I need help with this please!
Many thanks

d_stranz
21st January 2017, 00:42
You generally can't call methods on UI objects from any thread except the main thread (the one that starts when your application does). All of the UI objects live in this main thread. You can't create or modify UI objects from any other thread.

The only good way to update something in a UI object from a different thread is to make a signal / slot connection between the UI object and the worker thread. The signal will be handled properly across threads and the slot will be executed in the UI thread by the Qt event loop running in that thread, so no need for mutexes or other synchronization.

dfroze
21st January 2017, 16:09
Thank you @d_stranz for your fast response.

I've modified it, seems that after I added the signal/slot style and fixed a memory leak (yeah, this somehow affected the behavior as well), it started to work ok, for now ... I'll be back with a final conclusion soon.

dfroze
23rd January 2017, 14:14
So far so good. Thank you.:D