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
    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 Offline
      J 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
      • 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?

        V Offline
        V Offline
        VRonin
        wrote on 25 Oct 2018, 09:28 last edited by VRonin
        #66

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

        Why do you stumble on limitations in your imaginations here?

        Honestly I just think I'm not smart enough to get into this. It wouldn't be the first time. On the other hand I'd be really happy to see how it could be implemented so I could learn something new

        "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
        0
        • S sierdzio
          25 Oct 2018, 09:24

          @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.

          E Offline
          E Offline
          elfring
          wrote on 25 Oct 2018, 09:28 last edited by
          #67

          Show an API and it will be judged.

          Can this application programming interface be just “placement new” (which got the parameters “row” and “column” passed)?

          V 1 Reply Last reply 25 Oct 2018, 09:30
          0
          • E elfring
            25 Oct 2018, 09:28

            Show an API and it will be judged.

            Can this application programming interface be just “placement new” (which got the parameters “row” and “column” passed)?

            V Offline
            V Offline
            VRonin
            wrote on 25 Oct 2018, 09:30 last edited by VRonin
            #68

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

            Can this application programming interface be just “placement new” (which got the parameters “row” and “column” passed)?

            See, I struggle already, what would the return type be? (void* is a bit useless...)

            "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:33
            0
            • V VRonin
              25 Oct 2018, 09:30

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

              Can this application programming interface be just “placement new” (which got the parameters “row” and “column” passed)?

              See, I struggle already, what would the return type be? (void* is a bit useless...)

              E Offline
              E Offline
              elfring
              wrote on 25 Oct 2018, 09:33 last edited by
              #69

              See, I struggle already, what would the return type be?

              C++ new operators are returning non-void-pointer types, don't they?

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

                I still can't see a way forward.
                The simplest example would probably be QStringListModel. Could you help me understand how the placement new operator would work in that case?

                "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:44
                0
                • V VRonin
                  25 Oct 2018, 09:41

                  I still can't see a way forward.
                  The simplest example would probably be QStringListModel. Could you help me understand how the placement new operator would work in that case?

                  E Offline
                  E Offline
                  elfring
                  wrote on 25 Oct 2018, 09:44 last edited by
                  #71

                  Could you help me understand how the placement new operator would work in that case?

                  Can you understand already that “placement new” provides a pointer to an existing object?

                  V 1 Reply Last reply 25 Oct 2018, 09:49
                  0
                  • E elfring
                    25 Oct 2018, 09:44

                    Could you help me understand how the placement new operator would work in that case?

                    Can you understand already that “placement new” provides a pointer to an existing object?

                    V Offline
                    V Offline
                    VRonin
                    wrote on 25 Oct 2018, 09:49 last edited by
                    #72

                    Yes, I can't see a safe way to use that pointer though

                    "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:57
                    0
                    • V VRonin
                      25 Oct 2018, 09:49

                      Yes, I can't see a safe way to use that pointer though

                      E Offline
                      E Offline
                      elfring
                      wrote on 25 Oct 2018, 09:57 last edited by
                      #73

                      Yes,

                      I find this answer confusing in combination with the subsequent information.

                      I can't see a safe way to use that pointer though

                      You are used to the application of ordinary pointers.

                      auto x(new my_ball);
                      

                      How many ball variants would you manage by your QStringListModel example?

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        VRonin
                        wrote on 25 Oct 2018, 10:15 last edited by
                        #74

                        of, let's say you have a new that takes the row as an int parameter (QStringListModel has only 1 column).

                        I imagine that the implementation would check that the argument is within the range (row>=0 && row < lst.size() ) and then return something like &lst[row] (which is of type QString*).

                        Now we are back to the point we discussed here. How can we make sure that if the QString is modified then the dataChanged signal is sent?

                        "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, 12:28
                        2
                        • V VRonin
                          25 Oct 2018, 10:15

                          of, let's say you have a new that takes the row as an int parameter (QStringListModel has only 1 column).

                          I imagine that the implementation would check that the argument is within the range (row>=0 && row < lst.size() ) and then return something like &lst[row] (which is of type QString*).

                          Now we are back to the point we discussed here. How can we make sure that if the QString is modified then the dataChanged signal is sent?

                          E Offline
                          E Offline
                          elfring
                          wrote on 25 Oct 2018, 12:28 last edited by
                          #75

                          of, let's say you have a new that takes the row as an int parameter (QStringListModel has only 1 column).

                          I imagine that the implementation would check that the argument is within the range (row>=0 && row < lst.size()) and then return something like &lst[row] (which is of type QString*).

                          This kind of feedback fits also to my imaginations.

                          How can we make sure that if the QString is modified then the dataChanged signal is sent?

                          Corresponding solutions will become interesting if you would like to modify the determined string object at all.

                          V 1 Reply Last reply 25 Oct 2018, 13:44
                          0
                          • E elfring
                            25 Oct 2018, 12:28

                            of, let's say you have a new that takes the row as an int parameter (QStringListModel has only 1 column).

                            I imagine that the implementation would check that the argument is within the range (row>=0 && row < lst.size()) and then return something like &lst[row] (which is of type QString*).

                            This kind of feedback fits also to my imaginations.

                            How can we make sure that if the QString is modified then the dataChanged signal is sent?

                            Corresponding solutions will become interesting if you would like to modify the determined string object at all.

                            V Offline
                            V Offline
                            VRonin
                            wrote on 25 Oct 2018, 13:44 last edited by
                            #76

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

                            Corresponding solutions will become interesting

                            I agree but, once again I have no idea how to implement solutions. Do you?

                            "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, 15:17
                            0
                            • V VRonin
                              25 Oct 2018, 13:44

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

                              Corresponding solutions will become interesting

                              I agree but, once again I have no idea how to implement solutions. Do you?

                              E Offline
                              E Offline
                              elfring
                              wrote on 25 Oct 2018, 15:17 last edited by
                              #77

                              …, once again I have no idea how to implement solutions.

                              I find this hard to believe. It might take another while until you feel more comfortable with related software design approaches.

                              • A class can still offer functions which perform a specific change alone (as before the programming interface extension).
                              • The user class should take responsibility for mutable C++ references (as usual). Will it put special function calls into destructor implementations?
                              V 1 Reply Last reply 25 Oct 2018, 15:28
                              0
                              • E elfring
                                25 Oct 2018, 15:17

                                …, once again I have no idea how to implement solutions.

                                I find this hard to believe. It might take another while until you feel more comfortable with related software design approaches.

                                • A class can still offer functions which perform a specific change alone (as before the programming interface extension).
                                • The user class should take responsibility for mutable C++ references (as usual). Will it put special function calls into destructor implementations?
                                V Offline
                                V Offline
                                VRonin
                                wrote on 25 Oct 2018, 15:28 last edited by
                                #78

                                I find this hard to believe.

                                I'm not joking, I really can't think of a decent way

                                The user class should take responsibility for mutable C++ references

                                I disagree. This is a recipe for disaster

                                A class can still offer functions which perform a specific change alone

                                This might work for QStringListModel as all the elements are QString but as soon as you move just 1 step further and look at QListModel (the model behind QListWidget) where the stored data can be of any type, even a custom one defined by the user, your argument kinda falls apart, doesn't it?

                                "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, 18:40
                                2
                                • E elfring
                                  25 Oct 2018, 05:27

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

                                  K Offline
                                  K Offline
                                  kshegunov
                                  Moderators
                                  wrote on 25 Oct 2018, 15:42 last edited by
                                  #79

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

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

                                  Yes, but then I wonder does yours?

                                  You are used to the application of ordinary pointers.

                                  auto x(new my_ball);
                                  

                                  How many ball variants would you manage by your QStringListModel example?

                                  You don't seem to understand that the model is the boundary between the application-level code (i.e. user programmers) and the system-level code (for brevity only, it's the Qt library not the whole system). At that boundary the system code has to provide the means for the application code to map the data, and at the same time the library provides the display of said data.

                                  At the point when the system is compiled the application-level code does not exist, so the system-level programmer (in this case the Qt Project contributor) can not and will not use anything of type that's unknown to the system. Unknown types include every user type the application provides itself, granted the exception the system has put in place a way for the type to be made known to the system. The latter is done through the meta-type system in Qt, and QVariant is aware of it.

                                  Is your ball known (i.e. defined) when the models are developed? Of course not. Then the models can't in any conceivable way create that type. The models are generic and use QVariant so they can map multitude of types, not only your own ball.
                                  Again, provide code that demonstrates your idea, so we can have a reasonable discussion.

                                  Read and abide by the Qt Code of Conduct

                                  E 1 Reply Last reply 25 Oct 2018, 19:01
                                  2
                                  • V VRonin
                                    25 Oct 2018, 15:28

                                    I find this hard to believe.

                                    I'm not joking, I really can't think of a decent way

                                    The user class should take responsibility for mutable C++ references

                                    I disagree. This is a recipe for disaster

                                    A class can still offer functions which perform a specific change alone

                                    This might work for QStringListModel as all the elements are QString but as soon as you move just 1 step further and look at QListModel (the model behind QListWidget) where the stored data can be of any type, even a custom one defined by the user, your argument kinda falls apart, doesn't it?

                                    E Offline
                                    E Offline
                                    elfring
                                    wrote on 25 Oct 2018, 18:40 last edited by
                                    #80

                                    This is a recipe for disaster

                                    How many questionable applications do you notice then for the QVector class (for comparison)?

                                    …, your argument kinda falls apart, doesn't it?

                                    • This model is for private use by the widget so far, isn't it?
                                    • Can you eventually get a desire to fiddle with list elements from a data model directly?
                                    V 1 Reply Last reply 25 Oct 2018, 18:52
                                    0
                                    • E elfring
                                      25 Oct 2018, 18:40

                                      This is a recipe for disaster

                                      How many questionable applications do you notice then for the QVector class (for comparison)?

                                      …, your argument kinda falls apart, doesn't it?

                                      • This model is for private use by the widget so far, isn't it?
                                      • Can you eventually get a desire to fiddle with list elements from a data model directly?
                                      V Offline
                                      V Offline
                                      VRonin
                                      wrote on 25 Oct 2018, 18:52 last edited by
                                      #81

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

                                      How many questionable applications do you notice then for the QVector class (for comparison)?

                                      QVector is not a QObject subclass. it doesn't have to take care of sending signals to notify other parts of the program that something changed/was added/was removed/was moved.

                                      This model is for private use by the widget so far, isn't it?

                                      No. Absolutely not. I often use (and abuse) the model framework even in application that do not have a view.
                                      It's also used in QML.

                                      Can you eventually get a desire to fiddle with list elements from a data model directly?

                                      I don't because I realise how badly it can break the entire framework. The internals of the data model should be handled by the model only, not get exposed otherwise it becomes simply unmanageable

                                      "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
                                      2
                                      • K kshegunov
                                        25 Oct 2018, 15:42

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

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

                                        Yes, but then I wonder does yours?

                                        You are used to the application of ordinary pointers.

                                        auto x(new my_ball);
                                        

                                        How many ball variants would you manage by your QStringListModel example?

                                        You don't seem to understand that the model is the boundary between the application-level code (i.e. user programmers) and the system-level code (for brevity only, it's the Qt library not the whole system). At that boundary the system code has to provide the means for the application code to map the data, and at the same time the library provides the display of said data.

                                        At the point when the system is compiled the application-level code does not exist, so the system-level programmer (in this case the Qt Project contributor) can not and will not use anything of type that's unknown to the system. Unknown types include every user type the application provides itself, granted the exception the system has put in place a way for the type to be made known to the system. The latter is done through the meta-type system in Qt, and QVariant is aware of it.

                                        Is your ball known (i.e. defined) when the models are developed? Of course not. Then the models can't in any conceivable way create that type. The models are generic and use QVariant so they can map multitude of types, not only your own ball.
                                        Again, provide code that demonstrates your idea, so we can have a reasonable discussion.

                                        E Offline
                                        E Offline
                                        elfring
                                        wrote on 25 Oct 2018, 19:01 last edited by
                                        #82

                                        Is your ball known (i.e. defined) when the models are developed?

                                        Models can be implemented in the way that this can happen.

                                        Again, provide code that demonstrates your idea, …

                                        How do you think about to discuss concrete consequences for passing a pair of integer types (row, column) to a “placement new”?

                                        K 1 Reply Last reply 25 Oct 2018, 19:27
                                        0
                                        • E elfring
                                          25 Oct 2018, 19:01

                                          Is your ball known (i.e. defined) when the models are developed?

                                          Models can be implemented in the way that this can happen.

                                          Again, provide code that demonstrates your idea, …

                                          How do you think about to discuss concrete consequences for passing a pair of integer types (row, column) to a “placement new”?

                                          K Offline
                                          K Offline
                                          kshegunov
                                          Moderators
                                          wrote on 25 Oct 2018, 19:27 last edited by kshegunov
                                          #83

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

                                          Is your ball known (i.e. defined) when the models are developed?

                                          Models can be implemented in the way that this can happen.

                                          No they can't.

                                          How do you think about to discuss concrete consequences for passing a pair of integer types (row, column) to a “placement new”?

                                          I don't. I already stated directly and quite clearly what is needed to discuss - a proof of concept in code.

                                          Read and abide by the Qt Code of Conduct

                                          E 1 Reply Last reply 26 Oct 2018, 07:49
                                          1

                                          73/116

                                          25 Oct 2018, 09:57

                                          • Login

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