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. Increasing usage for C++ new operators based on data model indexes?

Increasing usage for C++ new operators based on data model indexes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
data modelscreateindexallocationnew operatorssoftware design
116 Posts 6 Posters 51.4k 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.
  • E elfring
    16 Oct 2018, 14:48

    userType() as already used

    This function returns the data type “int”.
    What would you like to say for pointers within data models?

    To clarify a single index can contain multiple data points of non-homogeneous data type

    This information seems to point an other software development concern out.
    Would you like to introduce another case distinction?

    V Offline
    V Offline
    VRonin
    wrote on 17 Oct 2018, 07:13 last edited by
    #46

    @elfring said in Increasing usage for C++ new operators based on data model indexes?:

    What would you like to say for pointers within data models?

    While my point is that you shouldn't use pointers as data because it create unclear ownership of that piece of memory, this constructor allows you to specify the usertype you want that pointer to be identified by

    @elfring said in Increasing usage for C++ new operators based on data model indexes?:

    This function returns the data type “int”.

    In C or C++ there's no alternative. You can't have a function that changes return type based on its body. The only way to downcast safely is to keep a track of what type you want to return (here an integer that represent the return value of qMetaTypeId<T>()).

    This information seems to point an other software development concern out.
    Would you like to introduce another case distinction?

    There's nothing new to introduce, different arguments to QModelIndex::data return different data roles.

    "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

    E 1 Reply Last reply 17 Oct 2018, 07:55
    2
    • V VRonin
      17 Oct 2018, 07:13

      @elfring said in Increasing usage for C++ new operators based on data model indexes?:

      What would you like to say for pointers within data models?

      While my point is that you shouldn't use pointers as data because it create unclear ownership of that piece of memory, this constructor allows you to specify the usertype you want that pointer to be identified by

      @elfring said in Increasing usage for C++ new operators based on data model indexes?:

      This function returns the data type “int”.

      In C or C++ there's no alternative. You can't have a function that changes return type based on its body. The only way to downcast safely is to keep a track of what type you want to return (here an integer that represent the return value of qMetaTypeId<T>()).

      This information seems to point an other software development concern out.
      Would you like to introduce another case distinction?

      There's nothing new to introduce, different arguments to QModelIndex::data return different data roles.

      E Offline
      E Offline
      elfring
      wrote on 17 Oct 2018, 07:55 last edited by
      #47

      While my point is that you shouldn't use pointers as data because it create unclear ownership of that piece of memory, …

      This is one way of thinking around the strict usage of value objects while I would prefer to avoid unnecessary data transfers as much as possible.
      The ownership information can be managed also by other means, can't it?

      The only way to downcast safely is to keep a track of what type you want to return …

      I imagine that additional software design options can be relevant here.

      …, different arguments to QModelIndex::data return different data roles.

      • “Data copies” are returned for each possible role.
      • Can any function provide a reference (and not a pointer) for a specific object within this data model?
      S V 2 Replies Last reply 17 Oct 2018, 08:00
      0
      • E elfring
        17 Oct 2018, 07:55

        While my point is that you shouldn't use pointers as data because it create unclear ownership of that piece of memory, …

        This is one way of thinking around the strict usage of value objects while I would prefer to avoid unnecessary data transfers as much as possible.
        The ownership information can be managed also by other means, can't it?

        The only way to downcast safely is to keep a track of what type you want to return …

        I imagine that additional software design options can be relevant here.

        …, different arguments to QModelIndex::data return different data roles.

        • “Data copies” are returned for each possible role.
        • Can any function provide a reference (and not a pointer) for a specific object within this data model?
        S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 17 Oct 2018, 08:00 last edited by
        #48

        @elfring said in Increasing usage for C++ new operators based on data model indexes?:

        I would prefer to avoid unnecessary data transfers as much as possible

        Recommended reading: John Carmack's take on functional programming

        (Z(:^

        1 Reply Last reply
        1
        • E elfring
          17 Oct 2018, 07:55

          While my point is that you shouldn't use pointers as data because it create unclear ownership of that piece of memory, …

          This is one way of thinking around the strict usage of value objects while I would prefer to avoid unnecessary data transfers as much as possible.
          The ownership information can be managed also by other means, can't it?

          The only way to downcast safely is to keep a track of what type you want to return …

          I imagine that additional software design options can be relevant here.

          …, different arguments to QModelIndex::data return different data roles.

          • “Data copies” are returned for each possible role.
          • Can any function provide a reference (and not a pointer) for a specific object within this data model?
          V Offline
          V Offline
          VRonin
          wrote on 17 Oct 2018, 08:37 last edited by
          #49

          @elfring said in Increasing usage for C++ new operators based on data model indexes?:

          I imagine that additional software design options can be relevant here.

          I haven't seen any better solution ever in my life

          The ownership information can be managed also by other means, can't it?

          Yes but as I said it becomes unclear. How can you assure a slot connected to, for example, dataChanged is not accessing memory the owner already deleted?

          “Data copies” are returned for each possible role.

          And this is the key point you don't understand. Qt uses a very cheap copy method (the implicit sharing) that is a basically a fancy std::shared_ptr. Copying by value a std::shared_ptr does not copy the data pointed by it.
          This covers any native and almost all Qt classes. Copying any of them by value has performance not significantly different from copying a pointer to those classes. Qt also give you the tools to apply that technology to your classes.
          This means that all operations that you call “Data copies” are actually copying a pointer (or memcpy up to 64 bits for native types) and adding 1 to a reference counter. As discussed above smart pointers and reference counters are the direction modern C++ is moving to.

          You can still think the "good old way" was better and that's fine but that can't influence the design of other projects that decide to go the "modern way"

          "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

          E 1 Reply Last reply 17 Oct 2018, 09:11
          5
          • V VRonin
            17 Oct 2018, 08:37

            @elfring said in Increasing usage for C++ new operators based on data model indexes?:

            I imagine that additional software design options can be relevant here.

            I haven't seen any better solution ever in my life

            The ownership information can be managed also by other means, can't it?

            Yes but as I said it becomes unclear. How can you assure a slot connected to, for example, dataChanged is not accessing memory the owner already deleted?

            “Data copies” are returned for each possible role.

            And this is the key point you don't understand. Qt uses a very cheap copy method (the implicit sharing) that is a basically a fancy std::shared_ptr. Copying by value a std::shared_ptr does not copy the data pointed by it.
            This covers any native and almost all Qt classes. Copying any of them by value has performance not significantly different from copying a pointer to those classes. Qt also give you the tools to apply that technology to your classes.
            This means that all operations that you call “Data copies” are actually copying a pointer (or memcpy up to 64 bits for native types) and adding 1 to a reference counter. As discussed above smart pointers and reference counters are the direction modern C++ is moving to.

            You can still think the "good old way" was better and that's fine but that can't influence the design of other projects that decide to go the "modern way"

            E Offline
            E Offline
            elfring
            wrote on 17 Oct 2018, 09:11 last edited by
            #50

            And this is the key point you don't understand.

            I got special software development views around the handling of data copies.

            … that can't influence the design of other projects that decide to go the "modern way"

            I find that it can be more important to distinguish an other design aspect than “software modernisation” here.
            I would occasionally like to get direct access to some memory locations also by the general programming interface of data models.

            The class “std::shared_ptr” supports the member functions “get” and “operator[]”.

            1 Reply Last reply
            0
            • V VRonin
              12 Oct 2018, 16:09

              @elfring said in Increasing usage for C++ new operators based on data model indexes?:

              An item can be added to a model. Its position is identified by a corresponding model index, isn't it?

              yes but the item exists even if no index points to it. just like an element in space exists even if nothing points to it

              A pointer from the heap can be used together with a simple index for a buffer (an array).

              I don't see ho this is related

              Do Qt data models manage just vectors of pointers internally?

              No, you are free to design the internals however you want

              Can the mentioned coordinate be connected then with a pointer for a specific object within the data model in a similar way?

              the coordinate "is" the pointer. the point being that given a QModelIndex the model can map 1:1 an item in its internal structure.

              Such descriptions can be generally helpful.

              The pdf book I linked should be a great starting point

              E Offline
              E Offline
              elfring
              wrote on 24 Oct 2018, 13:58 last edited by
              #51

              the coordinate "is" the pointer.

              Will software libraries evolve further around the suggestion “Add support for usage of placement new together with data model indexes”?

              kshegunovK 1 Reply Last reply 24 Oct 2018, 17:39
              0
              • E elfring
                24 Oct 2018, 13:58

                the coordinate "is" the pointer.

                Will software libraries evolve further around the suggestion “Add support for usage of placement new together with data model indexes”?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on 24 Oct 2018, 17:39 last edited by
                #52

                @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                Will software libraries evolve further around the suggestion “Add support for usage of placement new together with data model indexes”?

                No they will not.

                Read and abide by the Qt Code of Conduct

                E 1 Reply Last reply 24 Oct 2018, 20:02
                1
                • kshegunovK kshegunov
                  24 Oct 2018, 17:39

                  @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                  Will software libraries evolve further around the suggestion “Add support for usage of placement new together with data model indexes”?

                  No they will not.

                  E Offline
                  E Offline
                  elfring
                  wrote on 24 Oct 2018, 20:02 last edited by
                  #53

                  Why do you think in this direction?

                  kshegunovK 1 Reply Last reply 24 Oct 2018, 23:57
                  0
                  • E elfring
                    24 Oct 2018, 20:02

                    Why do you think in this direction?

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on 24 Oct 2018, 23:57 last edited by
                    #54

                    @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                    Why do you think in this direction?

                    Experience.

                    Read and abide by the Qt Code of Conduct

                    E 1 Reply Last reply 25 Oct 2018, 05:27
                    0
                    • kshegunovK kshegunov
                      24 Oct 2018, 23:57

                      @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                      Why do you think in this direction?

                      Experience.

                      E Offline
                      E Offline
                      elfring
                      wrote on 25 Oct 2018, 05:27 last edited by
                      #55

                      Does your software development experience include the usage of placement new?

                      V kshegunovK 2 Replies Last reply 25 Oct 2018, 07:57
                      0
                      • E elfring
                        25 Oct 2018, 05:27

                        Does your software development experience include the usage of placement new?

                        V Offline
                        V Offline
                        VRonin
                        wrote on 25 Oct 2018, 07:57 last edited by
                        #56

                        Does your software development experience include the usage of QAbstractItemModel?

                        I wouldn't question @kshegunov 's abilities as he's firmly in the top tier of developers contributing on this forum.

                        "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

                        E 1 Reply Last reply 25 Oct 2018, 08:45
                        1
                        • V VRonin
                          25 Oct 2018, 07:57

                          Does your software development experience include the usage of QAbstractItemModel?

                          I wouldn't question @kshegunov 's abilities as he's firmly in the top tier of developers contributing on this forum.

                          E Offline
                          E Offline
                          elfring
                          wrote on 25 Oct 2018, 08:45 last edited by
                          #57

                          Does your software development experience include the usage of QAbstractItemModel?

                          My knowledge is growing also in this software area.

                          … he's firmly in the top tier of developers contributing on this forum.

                          This is fine.

                          Our experiences are varying in several areas, don't they?

                          Understanding difficulties can happen then when someone (like me) dares to present special development ideas.

                          V 1 Reply Last reply 25 Oct 2018, 08:59
                          0
                          • E elfring
                            25 Oct 2018, 08:45

                            Does your software development experience include the usage of QAbstractItemModel?

                            My knowledge is growing also in this software area.

                            … he's firmly in the top tier of developers contributing on this forum.

                            This is fine.

                            Our experiences are varying in several areas, don't they?

                            Understanding difficulties can happen then when someone (like me) dares to present special development ideas.

                            V Offline
                            V Offline
                            VRonin
                            wrote on 25 Oct 2018, 08:59 last edited by
                            #58

                            @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                            Understanding difficulties can happen then when someone (like me) dares to present special development ideas.

                            Sorry if it came out wrongly before, we are not against new development ideas at all, not on this forum and not in the Qt Project.

                            I think what is clear from the discussion above is that nobody here can think of an elegant, efficient, functional and safe way to introduce the concept you suggest in the QAbstractItemModel (or any of its subclasses) interface.
                            Having said that, you are correct by saying

                            Our experiences are varying in several areas, don't they?

                            So our point is, if you have an idea for an implementation then please go ahead and propose it to the community. I'd be very happy to participate in the review process of such an innovation as well as I might end up learning something new (punt not intended)

                            "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

                            E 1 Reply Last reply 25 Oct 2018, 09:06
                            2
                            • V VRonin
                              25 Oct 2018, 08:59

                              @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                              Understanding difficulties can happen then when someone (like me) dares to present special development ideas.

                              Sorry if it came out wrongly before, we are not against new development ideas at all, not on this forum and not in the Qt Project.

                              I think what is clear from the discussion above is that nobody here can think of an elegant, efficient, functional and safe way to introduce the concept you suggest in the QAbstractItemModel (or any of its subclasses) interface.
                              Having said that, you are correct by saying

                              Our experiences are varying in several areas, don't they?

                              So our point is, if you have an idea for an implementation then please go ahead and propose it to the community. I'd be very happy to participate in the review process of such an innovation as well as I might end up learning something new (punt not intended)

                              E Offline
                              E Offline
                              elfring
                              wrote on 25 Oct 2018, 09:06 last edited by
                              #59

                              …, if you have an idea for an implementation then please go ahead and propose it to the community.

                              I guess that progress will depend on this basic clarification:
                              Are you familiar with the usage of placement new?

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                VRonin
                                wrote on 25 Oct 2018, 09:14 last edited by
                                #60

                                The project maintainers are seasoned (15-20 years experience) developers and are familiar with all aspects of standard C++ (especially its oldest parts like placement new).

                                It's safe to assume a total mastery of the placement new concept by people reviewing code, don't worry

                                "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

                                E 1 Reply Last reply 25 Oct 2018, 09:20
                                2
                                • V VRonin
                                  25 Oct 2018, 09:14

                                  The project maintainers are seasoned (15-20 years experience) developers and are familiar with all aspects of standard C++ (especially its oldest parts like placement new).

                                  It's safe to assume a total mastery of the placement new concept by people reviewing code, don't worry

                                  E Offline
                                  E Offline
                                  elfring
                                  wrote on 25 Oct 2018, 09:20 last edited by
                                  #61

                                  It's safe to assume a total mastery of the placement new concept by people reviewing code, don't worry

                                  This information is very promising.

                                  • Unfortunately, I could not extract corresponding indications of understanding for my proposal so far.
                                  • How would you like to clarify a possible mapping from data model indexes to pointers further?
                                  V S 2 Replies Last reply 25 Oct 2018, 09:22
                                  0
                                  • E elfring
                                    25 Oct 2018, 09:20

                                    It's safe to assume a total mastery of the placement new concept by people reviewing code, don't worry

                                    This information is very promising.

                                    • Unfortunately, I could not extract corresponding indications of understanding for my proposal so far.
                                    • How would you like to clarify a possible mapping from data model indexes to pointers further?
                                    V Offline
                                    V Offline
                                    VRonin
                                    wrote on 25 Oct 2018, 09:22 last edited by
                                    #62

                                    @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                                    How would you like to clarify a possible mapping from data model indexes to pointers further?

                                    That's what we are asking you to propose.
                                    We can't think of a way unfortunately

                                    "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

                                    E 1 Reply Last reply 25 Oct 2018, 09:23
                                    0
                                    • V VRonin
                                      25 Oct 2018, 09:22

                                      @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                                      How would you like to clarify a possible mapping from data model indexes to pointers further?

                                      That's what we are asking you to propose.
                                      We can't think of a way unfortunately

                                      E Offline
                                      E Offline
                                      elfring
                                      wrote on 25 Oct 2018, 09:23 last edited by
                                      #63

                                      We can't think of a way unfortunately

                                      Why do you stumble on limitations in your imaginations here?

                                      J.HilkJ V 2 Replies Last reply 25 Oct 2018, 09:26
                                      0
                                      • E elfring
                                        25 Oct 2018, 09:20

                                        It's safe to assume a total mastery of the placement new concept by people reviewing code, don't worry

                                        This information is very promising.

                                        • Unfortunately, I could not extract corresponding indications of understanding for my proposal so far.
                                        • How would you like to clarify a possible mapping from data model indexes to pointers further?
                                        S Offline
                                        S Offline
                                        sierdzio
                                        Moderators
                                        wrote on 25 Oct 2018, 09:24 last edited by
                                        #64

                                        @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                                        Unfortunately, I could not extract corresponding indications of understanding for my proposal so far.

                                        Because you have not proposed anything. Show an API and it will be judged. Show a usage example of that API and it will help us know if the API is convenient. Measure with benchmark and we'll know if it improves performance.

                                        Without concrete foundations, any idea can be argued endlessly without result.

                                        (Z(:^

                                        E 1 Reply Last reply 25 Oct 2018, 09:28
                                        2
                                        • E elfring
                                          25 Oct 2018, 09:23

                                          We can't think of a way unfortunately

                                          Why do you stumble on limitations in your imaginations here?

                                          J.HilkJ Offline
                                          J.HilkJ Offline
                                          J.Hilk
                                          Moderators
                                          wrote on 25 Oct 2018, 09:26 last edited by
                                          #65

                                          @elfring said in Increasing usage for C++ new operators based on data model indexes?:

                                          We can't think of a way unfortunately

                                          Why do you stumble on limitations in your imaginations here?

                                          I guess that will depend on this basic clarification:
                                          Are you familiar with the usage of placement new?


                                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                          Q: What's that?
                                          A: It's blue light.
                                          Q: What does it do?
                                          A: It turns blue.

                                          1 Reply Last reply
                                          0

                                          • Login

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