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. Proper place to store the selected item of a model
Forum Updated to NodeBB v4.3 + New Features

Proper place to store the selected item of a model

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 631 Views 2 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.
  • I Offline
    I Offline
    ivarec
    wrote on last edited by
    #1

    I'm developing an application that uses global configuration profiles, which can be saved and loaded by the user. Almost all screens are affected by what is the currently selected configuration profile.

    I'm in doubt about how to design this in Qt/QML. Should I implement this in the model, possibly by creating a "itemSelected" property and then some methods to read and edit it? Should I simply keep a reference in QML? What is considered a good practice in this case?

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

      Hi,

      Can you explain how you work with that global configuration profile ?

      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
      • I Offline
        I Offline
        ivarec
        wrote on last edited by
        #3

        Sorry for the late reply. For some reason, this forum is not notifying me of new messages.

        This global configuration is a state that gets transformed in an HTTP request to configure a third party system. Suppose that I have 20 parameters in this global configuration state. I might connect a slider to parameter 1, a checkbox to parameter 2, etc, until I have all of them available to my user through QML controls.

        When the user finally clicks a "Send" button, I get the current state of my global configuration and mash it into an HTTP request.

        My question is about good practices. I can see a lot of ways of doing this, but I want to know what's reasonable in Qt's land. Thanks a lot!

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Proper place to store the selected item of a model

          I didn't really understood the rest of the explanations but the answer to the title is either a QItemSelectionModel or, if it's just 1 item, a QPersistentModelIndex

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          4
          • I Offline
            I Offline
            ivarec
            wrote on last edited by
            #5

            I was misunderstanding some basic concepts about Qt models, such as that they don't have a "selected row" concept.

            What I need in the end was a model wrapper that can also hold an index. Qt offers this via the type DelegateModel.

            1 Reply Last reply
            1

            • Login

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