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?
QtWS25 Last Chance

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.3k 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

    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.

    VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on 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
    0
    • VRoninV VRonin

      @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 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?
      VRoninV 1 Reply Last reply
      0
      • E elfring

        …, 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?
        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on 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
        2
        • E elfring

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

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on 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
          2
          • VRoninV VRonin

            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 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?
            VRoninV 1 Reply Last reply
            0
            • E elfring

              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?
              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on 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
              • kshegunovK kshegunov

                @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 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”?

                kshegunovK 1 Reply Last reply
                0
                • E elfring

                  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”?

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on 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
                  1
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by VRonin
                    #84

                    I'll try to explain in layman terms why we are a bit frustrated by this and the related topics with a small parallel.
                    Imagine you walk into a car factory and say to the manager: "you should put wings on your cars"
                    The manager answers: "what would that achieve?"
                    you - "do you know what wings are?"
                    manager - "yes but I don't see how they can be useful on a car"
                    you - "wouldn't it be cool to have wings on the cars?!"
                    manager - "yes but wings are not enough to make the cars fly"
                    you - "that's right, you need to also make the cars fly"
                    manager - "fine but how am I supposed to do that?"
                    you - "It's something you should think about"
                    manager - "well if you don't have any idea how to make the cars fly, I don't see why i should put wings on my cars"
                    you - "wouldn't it be cool to have wings on the cars?!"

                    This is exactly what you are doing to us!

                    "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
                    7
                    • kshegunovK kshegunov

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

                      E Offline
                      E Offline
                      elfring
                      wrote on last edited by
                      #85

                      No they can't.

                      Why do you try to exclude the possibility that various data can be loaded into models?

                      … - a proof of concept in code.

                      Do any other aspects hinder you to discuss software design possibilities around returning pointers (or C++ references) from functions after a few parameters were passed?

                      kshegunovK 1 Reply Last reply
                      0
                      • VRoninV VRonin

                        I'll try to explain in layman terms why we are a bit frustrated by this and the related topics with a small parallel.
                        Imagine you walk into a car factory and say to the manager: "you should put wings on your cars"
                        The manager answers: "what would that achieve?"
                        you - "do you know what wings are?"
                        manager - "yes but I don't see how they can be useful on a car"
                        you - "wouldn't it be cool to have wings on the cars?!"
                        manager - "yes but wings are not enough to make the cars fly"
                        you - "that's right, you need to also make the cars fly"
                        manager - "fine but how am I supposed to do that?"
                        you - "It's something you should think about"
                        manager - "well if you don't have any idea how to make the cars fly, I don't see why i should put wings on my cars"
                        you - "wouldn't it be cool to have wings on the cars?!"

                        This is exactly what you are doing to us!

                        E Offline
                        E Offline
                        elfring
                        wrote on last edited by
                        #86

                        Why would you get frustrated by topics (which I presented)?

                        1 Reply Last reply
                        0
                        • E elfring

                          No they can't.

                          Why do you try to exclude the possibility that various data can be loaded into models?

                          … - a proof of concept in code.

                          Do any other aspects hinder you to discuss software design possibilities around returning pointers (or C++ references) from functions after a few parameters were passed?

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by kshegunov
                          #87

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

                          Why do you try to exclude the possibility that various data can be loaded into models?

                          I don't, and it already can through QVariant.

                          Do any other aspects hinder you to discuss software design possibilities around returning pointers (or C++ references) from functions after a few parameters were passed?

                          No. I want you to meet the burden or proof - if you claim something, have the balls to back it up. You claim to have an idea that's better than the currently available one, put it on paper, so to speak, and we can discuss it.

                          Read and abide by the Qt Code of Conduct

                          E 1 Reply Last reply
                          2
                          • kshegunovK kshegunov

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

                            Why do you try to exclude the possibility that various data can be loaded into models?

                            I don't, and it already can through QVariant.

                            Do any other aspects hinder you to discuss software design possibilities around returning pointers (or C++ references) from functions after a few parameters were passed?

                            No. I want you to meet the burden or proof - if you claim something, have the balls to back it up. You claim to have an idea that's better than the currently available one, put it on paper, so to speak, and we can discuss it.

                            E Offline
                            E Offline
                            elfring
                            wrote on last edited by
                            #88

                            You claim to have an idea that's better than the currently available one,

                            I got another software development idea which I find useful.

                            put it on paper,

                            I have described it in a few variants for this feature request already.

                            so to speak, and we can discuss it.

                            Another approach

                            • Function input:
                              Parameters like row and column
                            • Function output:
                              • Pointer ⇒ How likely is it that this function variant can be called “C++ new operator”?
                              • C++ reference ⇒ Would you like to use direct access for an object?
                            kshegunovK 1 Reply Last reply
                            0
                            • E elfring

                              You claim to have an idea that's better than the currently available one,

                              I got another software development idea which I find useful.

                              put it on paper,

                              I have described it in a few variants for this feature request already.

                              so to speak, and we can discuss it.

                              Another approach

                              • Function input:
                                Parameters like row and column
                              • Function output:
                                • Pointer ⇒ How likely is it that this function variant can be called “C++ new operator”?
                                • C++ reference ⇒ Would you like to use direct access for an object?
                              kshegunovK Offline
                              kshegunovK Offline
                              kshegunov
                              Moderators
                              wrote on last edited by
                              #89

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

                              I got another software development idea which I find useful.

                              Good. Make a proof of concept for it as well. We can discuss it after that.

                              I have described it in a few variants for this feature request already.

                              You have not written anything tangible for us to discuss. You can describe it all night long, but at the end of the day we have to have something to base the discussion on. Some kind of proposed code that is to replace the current approach and then we can compare and argue.

                              Another approach

                              Finish one of the approaches before jumping into the next one.

                              Read and abide by the Qt Code of Conduct

                              E 1 Reply Last reply
                              3
                              • kshegunovK kshegunov

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

                                I got another software development idea which I find useful.

                                Good. Make a proof of concept for it as well. We can discuss it after that.

                                I have described it in a few variants for this feature request already.

                                You have not written anything tangible for us to discuss. You can describe it all night long, but at the end of the day we have to have something to base the discussion on. Some kind of proposed code that is to replace the current approach and then we can compare and argue.

                                Another approach

                                Finish one of the approaches before jumping into the next one.

                                E Offline
                                E Offline
                                elfring
                                wrote on last edited by
                                #90

                                You have not written anything tangible for us to discuss.

                                Can you discuss the programming interface design for a single function in terms of concepts (without referring to source code examples)?

                                kshegunovK 1 Reply Last reply
                                -1
                                • E elfring

                                  You have not written anything tangible for us to discuss.

                                  Can you discuss the programming interface design for a single function in terms of concepts (without referring to source code examples)?

                                  kshegunovK Offline
                                  kshegunovK Offline
                                  kshegunov
                                  Moderators
                                  wrote on last edited by
                                  #91

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

                                  Can you discuss the programming interface design for a single function in terms of concepts (without referring to source code examples)?

                                  No. There's no interface design for single functions, plus if it's only one function, just write it down for us and we can take a stab at the issue.

                                  Read and abide by the Qt Code of Conduct

                                  E 1 Reply Last reply
                                  2
                                  • kshegunovK kshegunov

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

                                    Can you discuss the programming interface design for a single function in terms of concepts (without referring to source code examples)?

                                    No. There's no interface design for single functions, plus if it's only one function, just write it down for us and we can take a stab at the issue.

                                    E Offline
                                    E Offline
                                    elfring
                                    wrote on last edited by
                                    #92

                                    There's no interface design for single functions,

                                    I find this view questionable.

                                    plus if it's only one function, just write it down for us and we can take a stab at the issue.

                                    template<typename model_item, typename model_index> model_item * get_item_pointer(model_index mx);
                                    

                                    Can you discuss such a function template declaration better?

                                    kshegunovK 1 Reply Last reply
                                    0
                                    • E elfring

                                      There's no interface design for single functions,

                                      I find this view questionable.

                                      plus if it's only one function, just write it down for us and we can take a stab at the issue.

                                      template<typename model_item, typename model_index> model_item * get_item_pointer(model_index mx);
                                      

                                      Can you discuss such a function template declaration better?

                                      kshegunovK Offline
                                      kshegunovK Offline
                                      kshegunov
                                      Moderators
                                      wrote on last edited by kshegunov
                                      #93

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

                                      I find this view questionable.

                                      That's your right. I will not spend any time arguing it either way.

                                      Can you discuss such a function template declaration better?

                                      That's a declaration, moreover it's a template, so this declaration doesn't mean anything to me. I have no idea what it is to be doing. Neither can I know how this model_item is to be handled inside the model, nor what model_index is, since it's a generic template type. Additionally there's no clarity of how this function is to be integrated into the QObject derived models, because there are limitations of what moc can parse.

                                      Give us some solutions to these problems and I'd be happy to pitch in with ideas, critiques and even work. But only if you take the time to actually prepare something that can reasonably be discussed.

                                      Vague notes about theoretical constructs are not acceptable.

                                      Read and abide by the Qt Code of Conduct

                                      E 1 Reply Last reply
                                      3
                                      • kshegunovK kshegunov

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

                                        I find this view questionable.

                                        That's your right. I will not spend any time arguing it either way.

                                        Can you discuss such a function template declaration better?

                                        That's a declaration, moreover it's a template, so this declaration doesn't mean anything to me. I have no idea what it is to be doing. Neither can I know how this model_item is to be handled inside the model, nor what model_index is, since it's a generic template type. Additionally there's no clarity of how this function is to be integrated into the QObject derived models, because there are limitations of what moc can parse.

                                        Give us some solutions to these problems and I'd be happy to pitch in with ideas, critiques and even work. But only if you take the time to actually prepare something that can reasonably be discussed.

                                        Vague notes about theoretical constructs are not acceptable.

                                        E Offline
                                        E Offline
                                        elfring
                                        wrote on last edited by
                                        #94

                                        I have no idea what it is to be doing.

                                        Your understanding of this programming interface (and my API proposal) might be still incomplete at the moment.
                                        But I am confident that you know already what such a function should be doing: You get a pointer for an object based on the provided input data.

                                        …, since it's a generic template type.

                                        Can you become used to work with templates for software development and involved concepts?

                                        kshegunovK 1 Reply Last reply
                                        0
                                        • E elfring

                                          I have no idea what it is to be doing.

                                          Your understanding of this programming interface (and my API proposal) might be still incomplete at the moment.
                                          But I am confident that you know already what such a function should be doing: You get a pointer for an object based on the provided input data.

                                          …, since it's a generic template type.

                                          Can you become used to work with templates for software development and involved concepts?

                                          kshegunovK Offline
                                          kshegunovK Offline
                                          kshegunov
                                          Moderators
                                          wrote on last edited by
                                          #95

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

                                          Your understanding of this programming interface (and my API proposal) might be still incomplete at the moment.

                                          That is for sure, as you have not proposed an API.

                                          But I am confident that you know already what such a function should be doing: You get a pointer for an object based on the provided input data.

                                          Humor me.

                                          Can you become used to work with templates for software development and involved concepts?

                                          I already am.

                                          Read and abide by the Qt Code of Conduct

                                          E 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