Refreshing a Qt form - Seems stuck - c++

My Qt form has a table and some labels. The table content and label contents changes so fast that sometimes it seems that the form is stuck. However when I minimize the form and maximize it again the latest values appear. Any suggestions on resolving this issue.

Do not update the user interface thousands of times per second. The image you see on the display is usually updated only 60 times per second. If you have CRT display the refresh rate may be something like 50 Hz - 120 Hz, but in most displays the refresh rate is 60 Hz.
There is absolutely no need to update contents of labels more often than the display's refresh rate is. The content is never seen. But updating the user interface widgets is quite costly, so it is expected that the window seems to be frozen. You are doing a lot of unnecessary work.
Do not update the widgets every time that your data changes. Use a timer to update the widgets. Timer interval of 16 ms means that the widgets are updated about 60 times per second. But even slower update rate is most probably good enough.

My suggestion is using repaint() after chaning the items:
Repaints the widget directly by calling paintEvent() immediately,
unless updates are disabled or the widget is hidden.
We suggest only using repaint() if you need an immediate repaint, for
example during animation. In almost all circumstances update() is
better, as it permits Qt to optimize for speed and minimize flicker.
Instead of direct calling, you can connect a signal to that widget, because repaint() is a slot.

My crystal ball suggests that you are using a custom model for a QTableWidget, yet your custom model does not emit the dataChanged signal properly. Your post does not contain enough data -- what kind of "a table" are you using, and how do you provide data to it?

Completely agree with Roku answer. There is no need to update user interface with a speed faster then user can read it. I doubt that something which is more 2-3 times per second has any sense for update.. Ok, if you using smart delegates like progress bars in grid or other visual things you can go up to 5-10 times a second.. but still it's never a point to implement grid updates 1000 times a second

Related

How do you display rapidly updating data to the user in a win32 GUI app?

So im building a basic win32 GUI app and I have a vector of data that gets constantly updated through an external source via a port. Im interested in displaying that list of data to the user but im not sure the best approach to go about it without causing update flickering.
I originally had an edit box in which I build a string with the information and update the window. But it has proved troublesome as the amount of data grows since I cant scroll down to look at additional data. Any ideas?
My idea is no point of updating the visual control as the same speed you receive the data. Because even-though you update at the same speed the users cannot see that change at the speed of data receiving. Human eye does not see a change happening in speed as 1/8th of a second. So better to update the visual control in a controlled manner. Maybe using a timer.
Appending to the text of an edit control for each subsequent data point will lead to flickering as the whole control re-renders as the text has changed.
I'd advise one of the following options:
1) use a ListBox or ListView control; when you add another row item, it only re-draws the new/changed/scrolled item. https://learn.microsoft.com/en-us/windows/desktop/controls/create-a-simple-list-box and https://learn.microsoft.com/en-us/windows/desktop/controls/list-view-controls-overview
2) If you only want an always-scrolling list of data, consider just having a command-line application that writes to the standard output and saves you a lot of trouble - cout or printf your data.
You can also use EM_SETSEL and EM_SCROLLCARET to automatically scroll, but also check the position of the scroll bar before doing that. If not at the bottom, it means that the user wanted to pause, so you can scroll.
Also, you can have the scroll lock key checked in order whether to scroll or not, after all that is what it's name is supposed to do.

BehaviorRelay/Variable slow RxDataSources if a lot of data in UITableview

Using RxDataSources I have a UITableView with a lot of sections and cells. When I search and replace the data with a new data source, my UI is blocked.
I have tried throttle and debounce, but if I search at the 'right' moment, then the UI still gets blocked for 1-2 sec.
Anyway I can solve this?
The problem was that too many animations were done at the same time. I used decideViewTransition to decide when it should animate.

WXWidgets TextCtrl or RichTextCtrl

I'm using wxWidgets for a log window of a piece of software which runs for many hours. The log can accumulate 10,000's of entries. Does the community have a suggestion for how not to have the GUI thread choke for many seconds when updating a textctrl or richtextctrl with this many lines? I'm open to using either control type but richtext is preferable to I can highlight warnings or errors.
It's currently set to readonly, so undo, redo, paste, etc are not active. I'm currently freezing and thawing it before and after adding content.
In a test case, I add 10000 lines to the text control with a freeze and thaw before and after. This operation still takes over a minute. Are these text controls simply incapable of handling long content?
Assuming your display is like a log, where each "line" is it's own entry, try using the wxListCtrl in "virtual mode". Basically, you maintain the data in your own control (a vector, array, whatever works) and the control asks you for only the data that is currently visible.
Inherit wxListCtrl with your own class and implement OnGetItem. When a row is visible, your derived control will have this method called for each row (and each column if you implement multiple columns) and you provide it with the data for that row, accessed directly from your array (list, vector, whatever).
More information is available in the wxWidgets docs here: http://docs.wxwidgets.org/3.0/classwx_list_ctrl.html#a92370967f97215e6068326645ee76624
The suggestion to use wxListCtrl in #avariant answer is a good one, however a wxTextCtrl with wxTE_RICH style should still be capable of appending 10000 lines in well less than a minute if you freeze/thaw it before/after. I'd be curious to know if you can reproduce the problem in the text sample included with wxWidgets (which already has a menu item doing something like this) and, if so, which wxWidgets port do you use.

Is there any way with Calabash to Query ALL objects in a screen? (really all)

With Calabash, the Query("all *") gets about twice as much data as the query("*") alone does, but I still have data I cannot read without complex scroll logic.
Is there any good way to get a true 'All' data from a screen without scrolling?
For example, I have a screen with 12 containers each with 5-10 distinct pieces of data. I need to be able to read my containers to validate the data on the page.
query returns all visible views.
query("all *") disables the visibility heuristics and returns all views.
Even when using all, some part of the view rect must exist within the bounds of the screen.
without scrolling
If you are using Calabash iOS, you can try the scroll_to_* methods which are documented here:
http://calabashapi.xamarin.com/ios/Calabash/Cucumber/Core.html
scroll_to_mark is the most generic - I recommend starting with that method.

Refresh text shown in a GTK+ widget?

Being resonably new to using GTK+, im not fully aware of all its functionality.
Basically, I have a GtkTreeView widget that has 4 Columns. I need to update the text displayed in the 4 columns every couple of seconds, but im not aware how to do this in GTK+.
I'm aware that I could flush the data using gtk_tree_store_clear, but I'm not sure how to repopulate the columns and have the top level window refresh to show this new data?
You need to get a GtkTreeIter to the proper row, then use the appropriate (model-specific) setter to change the data.
For instance gtk_list_store_set() for the GtkListStore model.
There is no need to clear the entire model if you just want to change some of the data, that is very wasteful and slow.
If you really need to change all the data, then sure, clear it.
You don't have to worry about getting the display to refresh; the view listens to events from the model, and automatically knows to refresh when the model changes.
UPDATE:
When changing the data (as described in commment), you don't need to "flush" the old data. The model owns the data, and knows how to keep track of the memory used. You just use the above-mentioned gtk_list_store_set() call as necessary to put the new desired data in the model. You can do this as often as necessary, and an update frequency of once every few seconds should be no problem at all.
Of course, in such a case, to keep your application (which I assume is single-threaded, for simplicity) responsive, you must have a way to asynchronously trigger an update, perhaps using a timer. Have a look at glib's g_timeout_add() function to learn how to add a simple global timer.