segmentation fault on mouse hover
im gonna explain my structure step by step
i have a widget including a button and a label
label has a png as background.
when i click on button a thread is being created
that thread draws a line chart on that label
here is my problem:
when i move my mouse on the png ,my application exits with segmentation fault
i read data from an array to draw the chart. i update array in another thread.
i have 2 mutexes to make my threads work consecutively. "1 update 1 draw" i mean.
draw function adds lines to my scene/view
another problem:
if i dont call msleep(30+) after each loop in each thread my program exits with fault again
30+ = ms under 30 doesnt work also :(
if needed i can post my code.
i need ur help.
have a good day every1
ersin özkan
turkey
Re: segmentation fault on mouse hover
Worker threads are forbidden from drawing anything on widgets. You have to draw from within the main thread.
Re: segmentation fault on mouse hover
but main thread doesnt update the scene immediately after my thread finish adding lineitems. so i call update() inside thread and it works. but when i mouse over i get error
Re: segmentation fault on mouse hover
There is no "but". You simply can't draw from within worker threads and that's final or else you'll be getting crashes at random moments and that's exactly what is happening. Use signals and slots or custom events to transfer data across threads.
Re: segmentation fault on mouse hover
wysota; should i do the "addLine to scene" work in main widget also?
ty for help
Re: segmentation fault on mouse hover
I am not sure if this will work -
Pass a canvas / paint device to the thread, and use it in the paint event of the main widget.
The thread will draw on the canvas while the canvas is member of main widget, hence it can be accessed from the paint event of main widget. :)
Re: segmentation fault on mouse hover
Quote:
Originally Posted by
elessaar
wysota; should i do the "addLine to scene" work in main widget also?
All QWidgets are not thread-safe (nor even reentrant as far as I remember) thus all actions related to widgets have to be done from the main thread unless the docs explicitely state otherwise for a particular operation. QGraphicsScene is not a QWidget but it is tightly related to it, so it might not be safe to interface it directly from an external thread. I really suggest you stick to signals and slots if you need multithreading (if you do).