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. Which model and item classes should I use to display custom items in a table and in a combo box?
Forum Updated to NodeBB v4.3 + New Features

Which model and item classes should I use to display custom items in a table and in a combo box?

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 6 Posters 3.0k Views 5 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #8

    You know that you can reuse the same model with several widgets ?

    The model / view framework is about that. You can have many views on top of a single model. The views do not need to be tables or lists.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DL5EU
      wrote on last edited by
      #9

      @SGaist : Yes, I know, and that is one reason why I would like to use it, but I don't see how this is related to my question concerning the submit() method. I must be missing something... :-)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #10

        My answer was regarding the use of QSettings to share the data around different objects of your application.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DL5EU
          wrote on last edited by
          #11

          Oh, I see, but I was confused because you talked about the model. I create a QSettings object wherever I need to access the settings. The documentation states that creating and destroying a settings object is very fast. I set the organization and application name in main() so that I can use QSetting's default constructor.

          Pl45m4P 1 Reply Last reply
          0
          • D DL5EU

            Oh, I see, but I was confused because you talked about the model. I create a QSettings object wherever I need to access the settings. The documentation states that creating and destroying a settings object is very fast. I set the organization and application name in main() so that I can use QSetting's default constructor.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #12

            @DL5EU

            But that's not what QSettings is meant for :)
            You save settings to store them on your disk and read them again when you start your app the next time.


            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
            0
            • D Offline
              D Offline
              DL5EU
              wrote on last edited by
              #13

              @Pl45m4 : yes, that is what I want to do. But what if I need information from the settings store at different places in my application? Should I create a global settings object (singleton)? This is not what I understand when I read the docs. Of course I might be wrong, so if there is a better way, please let me know.

              To me, settings are not only window positions and sizes but everything that is related to the configuration of the application. In my current case, the user has to set up a device configuration the first time he or she starts the application (device name (e.g. XYZ), device class (e.g. multimeter), device model (e.g. 34401A) and address (e.g. GPIB0::12::INSTR)). Once set up, this configuration rarely changes.

              Is this my mistake? Should I store this in a configuration file instead of "normal" application settings? And how do I access it from different places in my application? This certainly changes from case to case but perhaps there are some guidelines or examples?

              JonBJ 1 Reply Last reply
              0
              • D DL5EU

                @Pl45m4 : yes, that is what I want to do. But what if I need information from the settings store at different places in my application? Should I create a global settings object (singleton)? This is not what I understand when I read the docs. Of course I might be wrong, so if there is a better way, please let me know.

                To me, settings are not only window positions and sizes but everything that is related to the configuration of the application. In my current case, the user has to set up a device configuration the first time he or she starts the application (device name (e.g. XYZ), device class (e.g. multimeter), device model (e.g. 34401A) and address (e.g. GPIB0::12::INSTR)). Once set up, this configuration rarely changes.

                Is this my mistake? Should I store this in a configuration file instead of "normal" application settings? And how do I access it from different places in my application? This certainly changes from case to case but perhaps there are some guidelines or examples?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #14

                @DL5EU
                I am not sure what point @Pl45m4 was making. It seems to me you can use QSettings for this if that is what you wish. You don't need any singleton, you can indeed create a QSettings object on the fly if you wish to.

                The only thing would be if the data gets "large", or you want to save some better "structure" for it. Then I might think about a proper database for it, perhaps a SQLite file. But if you have just a few "rows" and "columns" for your devices QSettings should be up to it.

                Pl45m4P 1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DL5EU
                  wrote on last edited by
                  #15

                  That's what I thought. There are about 30 devices max. to manage with only few information. The user selects an instrument by its name and in order to be able to address it correctly, the application needs to know what device class it is (e.g. generator or receiver/meter) which type (depending on the manufacturer different commands have to be sent) and the device address.

                  If more data was needed I would put it into a configuration file or a database.

                  JonBJ 1 Reply Last reply
                  0
                  • D DL5EU

                    That's what I thought. There are about 30 devices max. to manage with only few information. The user selects an instrument by its name and in order to be able to address it correctly, the application needs to know what device class it is (e.g. generator or receiver/meter) which type (depending on the manufacturer different commands have to be sent) and the device address.

                    If more data was needed I would put it into a configuration file or a database.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #16

                    @DL5EU
                    Well that is getting to > 100 items of information, I might find that a bit much to manage as keys in QSettings, up to you.

                    M 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @DL5EU
                      Well that is getting to > 100 items of information, I might find that a bit much to manage as keys in QSettings, up to you.

                      M Offline
                      M Offline
                      mpergand
                      wrote on last edited by mpergand
                      #17

                      There would be a lot to say about this…

                      IMO, QSettings should only store infos about the state of the app. Other data should be stored in the standard data location.
                      If you need to poke around data about the current device, IMO there’s a design issue somewhere.

                      In an app similar to yours dealing with devices, the main window knows nothing about the devices configuration, it is just informed when the device is changed by the user.

                      void EditorWindow::activeDeviceDidChange(Device* dev)
                      {
                      	// update the editor with new device
                      }
                      

                      The Device class knows only a few things about the device, only things to uniquely identify the device from the others (name, unique id) and the state of the device (online offline)

                      Actually, the device class doesn’t know how to communicate to the device, that’s the role of the device manager.

                      The Device manager knows all the characteristics of the device and how to deal with it:

                      DeviceManager* manager=dev->deviceManager();
                      manager->initDevice();
                      

                      The device manager can also load/save data specific to this device, so the device can be reconfigured as it was next time the app is launched.

                      To sum up, in the data location of my app, I have this files:
                      Devices.data -> devices configuration
                      1425447_1 -> config data for this device unique id
                      6358425_2 -> idem

                      The only data saved in QSettings is the unique id of the active device.

                      1 Reply Last reply
                      3
                      • JonBJ JonB

                        @DL5EU
                        I am not sure what point @Pl45m4 was making. It seems to me you can use QSettings for this if that is what you wish. You don't need any singleton, you can indeed create a QSettings object on the fly if you wish to.

                        The only thing would be if the data gets "large", or you want to save some better "structure" for it. Then I might think about a proper database for it, perhaps a SQLite file. But if you have just a few "rows" and "columns" for your devices QSettings should be up to it.

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by Pl45m4
                        #18

                        @JonB said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                        I am not sure what point @Pl45m4 was making

                        You don't want to use QSettings to "share" stuff between classes at runtime, which is what @DL5EU is trying to achieve, I thought (maybe I'm wrong?!).
                        There are better ways to do that

                        I think @SGaist also got confused by this idea, that's why he asked.


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

                        ~E. W. Dijkstra

                        JonBJ 1 Reply Last reply
                        0
                        • Pl45m4P Pl45m4

                          @JonB said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                          I am not sure what point @Pl45m4 was making

                          You don't want to use QSettings to "share" stuff between classes at runtime, which is what @DL5EU is trying to achieve, I thought (maybe I'm wrong?!).
                          There are better ways to do that

                          I think @SGaist also got confused by this idea, that's why he asked.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #19

                          @Pl45m4 said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                          You don't want to use QSettings to "share" stuff between classes at runtime

                          Just don't know what you mean. QSettings is just an example of (effectively external/persistent) storage, if you want to use it to share some data between whatever then you can.

                          Having said that, I did say earlier that I actually think 30 rows x a few columns is a lot more data than I would want to share in a QSettings. Not that it wouldn't work, just I wouldn't choose it. I think the OP should look at various suggestions from @mpergand anyway.

                          Pl45m4P 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @Pl45m4 said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                            You don't want to use QSettings to "share" stuff between classes at runtime

                            Just don't know what you mean. QSettings is just an example of (effectively external/persistent) storage, if you want to use it to share some data between whatever then you can.

                            Having said that, I did say earlier that I actually think 30 rows x a few columns is a lot more data than I would want to share in a QSettings. Not that it wouldn't work, just I wouldn't choose it. I think the OP should look at various suggestions from @mpergand anyway.

                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by Pl45m4
                            #20

                            @JonB said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                            Just don't know what you mean. QSettings is just an example of (effectively external/persistent) storage, if you want to use it to share some data between whatever then you can.

                            for sure you can, but in my eyes it's a quite weird approach.

                            I personally would use QSettings only for the case, described in the documentation: to store real "settings" for later use in different sessions

                            • https://doc.qt.io/qt-5/qsettings.html#details

                            As you ( @JonB ) wrote above, if the data is getting bigger, i.e. more than just some "settings", it only makes it more complicated and harder to manage.


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

                            ~E. W. Dijkstra

                            JonBJ 1 Reply Last reply
                            0
                            • Pl45m4P Pl45m4

                              @JonB said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                              Just don't know what you mean. QSettings is just an example of (effectively external/persistent) storage, if you want to use it to share some data between whatever then you can.

                              for sure you can, but in my eyes it's a quite weird approach.

                              I personally would use QSettings only for the case, described in the documentation: to store real "settings" for later use in different sessions

                              • https://doc.qt.io/qt-5/qsettings.html#details

                              As you ( @JonB ) wrote above, if the data is getting bigger, i.e. more than just some "settings", it only makes it more complicated and harder to manage.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #21

                              @Pl45m4 said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                              I personally would use QSettings only for the case, described in the documentation: to store real "settings" for later use in different sessions

                              I do not disagree with you (=> I agree with you) :) I understand your point now. I thought the OP did want to save for future sessions, e.g.

                              I would like to save the device information in the settings store with a QSettings object [...] and written to the settings store.

                              But if you are right and the OP does not want storage for future re-use (i.e. only for use within this session) then I would not pick QSettings. If that is the case then in-memory should be adequate, no backing storage.

                              Pl45m4P 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @Pl45m4 said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                                I personally would use QSettings only for the case, described in the documentation: to store real "settings" for later use in different sessions

                                I do not disagree with you (=> I agree with you) :) I understand your point now. I thought the OP did want to save for future sessions, e.g.

                                I would like to save the device information in the settings store with a QSettings object [...] and written to the settings store.

                                But if you are right and the OP does not want storage for future re-use (i.e. only for use within this session) then I would not pick QSettings. If that is the case then in-memory should be adequate, no backing storage.

                                Pl45m4P Offline
                                Pl45m4P Offline
                                Pl45m4
                                wrote on last edited by Pl45m4
                                #22

                                @JonB said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                                I thought the OP did want to save for future sessions

                                Yes, but that became clear later. The initial post sounded like sharing data using QSettings between modules / classes of the same program and session :)
                                That's why I asked in my first reply ;-)

                                This is the part I am referring to ;-)

                                @DL5EU said in Which model and item classes should I use to display custom items in a table and in a combo box?:

                                I would like to save the device information in the settings store with a QSettings object (read and write methods exist). When editing is done, I would like to set the values of the settings so that they are available to other objects of the application and written to the settings store.

                                "When editing is done.... available to other objects of the app..."

                                Sounds a bit like same session and not really a use case for QSettings... ;-)

                                @DL5EU don't worry, everything's fine :) you can use QSettings. The situation wasn't really clear to me at first


                                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
                                • D Offline
                                  D Offline
                                  DL5EU
                                  wrote on last edited by
                                  #23

                                  Dear all,

                                  it seems to me that I really have a lot to learn :-) I must admit that I don't have much experience in OOP, nor in Qt.

                                  In my application I would like to control measurement instruments (e.g. generators and meters) to measure frequency responses and other things. The device information I am talking about is needed to create the corresponding device objects for the measurement functions. As every instrument has different commands e.g. to set the frequency or read the measured value, I need information concerning the device class (scope, meter, generator,...) the type (34401, 54616, SMY01) and of course the address on the GPIB to open a connection to the instrument. So I have to set up a persistent configuration that is read whenever the application is started. Additionally, this information is or might be needed at different places in the application. Perhaps the settings store is not the right place to store this kind of information, even if it is technically possible.

                                  Ralf

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #24

                                    Looks like you rather need to store that information in some sort of database or configuration file(s).

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • M mpergand referenced this topic on
                                    • M mpergand referenced this topic on

                                    • Login

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