Storing and setting widget values using arrays?
-
So i have many knobs, sliders, lineedits and they all have values obviously, but now as they are getting more and more i was looking to just store the values in a way that its exactly clear which value belongs to which widget and so i can set and store all the values at once using a loop or so.
Any recommendations on how to do that? Is it possible to have arrays which various ui widgets stored in them?
Also till now i've declared them and added that to layouts all by hand is there an easier approach that makes the code less cluttered?Thanks in advance. :) Have a nice day.
-
@StudentScripter said in Storing and setting widget values using arrays?:
i was looking to just store the values in a way that its exactly clear which value belongs to which widget
I mean, each widget already stores its value or data.
If you still want to store it separately, you could use a
struct
,QMap
/QHash
or some data model (not all widgets support that).Is it possible to have arrays which various ui widgets stored in them?
QVector<QWidget* >
?! Why should it not be possible?Also till now i've declared them and added that to layouts all by hand is there an easier approach that makes the code less cluttered?
Either add widgets by code or use
.ui
files. There is no other way :) -
@StudentScripter
You can put pointers to widgets into arrays/lists/maps as you please and use those for iterating through them etc.You can't get Designer to do that for you, so you have to manually populate the arrays/lists from the
ui->...
instance variables yourself (aftersetupUi()
).You can also visit all widgets of a given type, without setting anything up, via
topWidget->findChildren<QLineEdit *>()
.You can "group" widgets at design-time by e.g. creating a "holding" container
QWidget
orQFrame
orQGroupBox
if that helps. For buttons there is alsoQButtonGroup
.