Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Storing and setting widget values using arrays?
QtWS25 Last Chance

Storing and setting widget values using arrays?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt c++arraywidgetlayout
3 Posts 3 Posters 491 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StudentScripter
    wrote on 19 Mar 2024, 11:43 last edited by
    #1

    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.

    P J 2 Replies Last reply 19 Mar 2024, 11:52
    0
    • S StudentScripter
      19 Mar 2024, 11:43

      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.

      P Offline
      P Offline
      Pl45m4
      wrote on 19 Mar 2024, 11:52 last edited by Pl45m4
      #2

      @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 :)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • S StudentScripter
        19 Mar 2024, 11:43

        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.

        J Offline
        J Offline
        JonB
        wrote on 19 Mar 2024, 11:54 last edited by
        #3

        @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 (after setupUi()).

        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 or QFrame or QGroupBox if that helps. For buttons there is also QButtonGroup.

        1 Reply Last reply
        1

        3/3

        19 Mar 2024, 11:54

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved