Python Forum
[PyQt] graphyview setdata() doesn't work after recieving a mount of data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] graphyview setdata() doesn't work after recieving a mount of data
#1
Sorry about my bad English
I designed UI with UIdesigner, and I wrote four threads to handle the interface, serial port, calculation and drawing(all create by Qthread).
[Image: 20231121190929.png]
The window I draw on is upgraded through UIdesigner's Graphyview.
There is no problem when receiving data within an uncertain period of time, such as within about 1 minute, the serial port receives row data and passes it to the interface for display and calculation. After calculation, The new data is loaded into the list and used for drawing, the drawing function is used by [.setdata(list )]
[Image: 20231121192824.png]
you can see the lastest data is used as the label too. but few moment later, 1st painting stuck and then 2nd painting stuck ten seconds later,after a while, it will get stuck one after another but interface and label still work. Most of them are stuck in sequence, sometimes in disorder.
after drawing stuck, I also clicked the button of [.setdata(zero*200_list )] to no avail.The faster the receiving serial port frequency is, the faster the image will be stuck.
Add one more, Super fast data also makes my interface freeze until I click any button.So I controlled the sending speed of the slave computer.


what I have tryed:
①Delete oldest data which in the interface to reduce memory.(doesn't work)
②Carefully screen the received data, and incorrect data will not be use for [.setdata()].(doesn't work)
③I once thought that the drawing thread was too busy with calculations, so I added a fourth thread: calculation. Computing without threads also has this problem.(doesn't work)
④I didn't do long-term testing at first.Rolling my code back to the earliest version, accepting data and drawing directly also has this problem.(doesn't work)
⑤Use [.repaint()] or [.replot()] when stuck.(doesn't work, may be worng object?)
⑥I used redefinition for the escape key.The drawing will be updated when cancel the exit or switch to other software pages, it breaks me down.
⑦I remove the other code and just keep the loop drawing which also causes the stuck, I think Frequent [.setdata()] will cause stuck maybe.


My question:
①why doesn't [.setdata()] work?
②I only update all the graphs once I receive the data once, why are they stuck one by one?
③The most important ,how to fix it?


Sorry to bother you, thank you very much for watching Heart Heart Heart Heart
Reply
#2
An awesome person in the QT forum told me:"Qt requires the UI only be updated by the main thread. Secondary thread may appear to work, but is not reliable."
After moving part of the code that changes the graph UI in the drawing thread to the main thread, the probability of it getting stuck is greatly reduced. Even under high frequency conditions, one or two will occasionally get stuck after ten minutes, and not one after another.

You can use me as a negative example. Dont change any UI in other sub-thread so frequencily Hand Hand Hand
Reply
#3
(Nov-22-2023, 08:26 AM)ugly_curry_garlic Wrote: An awesome person in the QT forum told me:"Qt requires the UI only be updated by the main thread. Secondary thread may appear to work, but is not reliable."
After moving part of the code that changes the graph UI in the drawing thread to the main thread, the probability of it getting stuck is greatly reduced. Even under high frequency conditions, one or two will occasionally get stuck after ten minutes, and not one after another.

You can use me as a negative example. Dont change any UI in other sub-thread so frequencily Hand Hand Hand

But I'm still hoping someone can tell me how I can permanently fix this stuck situation
Reply
#4
Can you please post your code as text (using the Python button)? Images of code are useless.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Scrollbar doesn't work on Canvas in Tkinter DeanAseraf1 3 9,393 Sep-19-2019, 03:26 PM
Last Post: joe_momma
  [Kivy] Installed but doesn't work antonmichel 13 13,792 Jan-30-2018, 10:34 AM
Last Post: antonmichel
  [Tkinter] canvas.create_text doesn't work in a function vmarinelli 2 6,925 Jan-18-2018, 09:31 AM
Last Post: vmarinelli
  Gtk justification doesn't work rebelxt 2 4,535 Nov-05-2016, 01:52 PM
Last Post: rebelxt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020