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 of references for non-value objects?
Forum Update on Monday, May 27th 2025

Increasing usage of references for non-value objects?

Scheduled Pinned Locked Moved Unsolved General and Desktop
data modelsreferencesvalue objectscopyingsoftware design
30 Posts 5 Posters 6.9k 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
    2 Oct 2018, 09:31

    When you edit the data in-place, how will you notify the view that you have edited the data?

    The signal “itemChanged” should be emitted, shouldn't it?

    J Offline
    J Offline
    JKSH
    Moderators
    wrote on 2 Oct 2018, 14:04 last edited by
    #19

    @elfring said in Increasing usage of references for non-value objects?:

    When you edit the data in-place, how will you notify the view that you have edited the data?

    The signal “itemChanged” should be emitted, shouldn't it?

    Good! You're right, the object needs to emit a signal to notify the view.

    Next thing to think about: If you get a pointer/reference to the data inside a QStandardItem and you modify the object directly... how can you emit the "itemChanged()" signal?

    @elfring said in Increasing usage of references for non-value objects?:

    • Programming interfaces which return pointers can be encapsulated so that null pointer checks will be performed at fewer source code places.
    • Model adaptors
    • Occasional Qt object construction without default parameters

    I'll have a look through these ideas and reply later.

    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

    E 1 Reply Last reply 2 Oct 2018, 14:30
    1
    • J JKSH
      2 Oct 2018, 14:04

      @elfring said in Increasing usage of references for non-value objects?:

      When you edit the data in-place, how will you notify the view that you have edited the data?

      The signal “itemChanged” should be emitted, shouldn't it?

      Good! You're right, the object needs to emit a signal to notify the view.

      Next thing to think about: If you get a pointer/reference to the data inside a QStandardItem and you modify the object directly... how can you emit the "itemChanged()" signal?

      @elfring said in Increasing usage of references for non-value objects?:

      • Programming interfaces which return pointers can be encapsulated so that null pointer checks will be performed at fewer source code places.
      • Model adaptors
      • Occasional Qt object construction without default parameters

      I'll have a look through these ideas and reply later.

      E Offline
      E Offline
      elfring
      wrote on 2 Oct 2018, 14:30 last edited by
      #20

      how can you emit the "itemChanged()" signal?

      I would use a simple function call for this purpose.
      Are you looking for any other answer?

      J 1 Reply Last reply 2 Oct 2018, 14:48
      0
      • V Offline
        V Offline
        VRonin
        wrote on 2 Oct 2018, 14:45 last edited by
        #21

        You are over engineering.
        You don't need to reinvent the wheel. Just make your custom data class use implicit sharing as well. This way you can extract it from a variant cheaply (only a pointer is copied).

        Modifying the internal object from outside the model and then emitting the dataChanged manually is a hack and a breach of S.O.L.I.D

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

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

        1 Reply Last reply
        4
        • E elfring
          2 Oct 2018, 14:30

          how can you emit the "itemChanged()" signal?

          I would use a simple function call for this purpose.
          Are you looking for any other answer?

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 2 Oct 2018, 14:48 last edited by JKSH 10 Feb 2018, 14:57
          #22

          @elfring said in Increasing usage of references for non-value objects?:

          how can you emit the "itemChanged()" signal?

          I would use a simple function call for this purpose.
          Are you looking for any other answer?

          I need you to think about it some more.

          Imagine these methods become available in a future version of Qt:

          • QVariant& QStandardItem::dataRef(int role)
          • void* QVariant::internalPointer()

          These are the kinds of "extensions" that you wanted when you said "Increasing usage of references for non-value objects" right?

          With these functions, are you sure you can modify the data inside a QStandardItem without copying anything AND emit the required signal? Write some example code to try it.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          E 2 Replies Last reply 2 Oct 2018, 15:07
          0
          • J JKSH
            2 Oct 2018, 14:48

            @elfring said in Increasing usage of references for non-value objects?:

            how can you emit the "itemChanged()" signal?

            I would use a simple function call for this purpose.
            Are you looking for any other answer?

            I need you to think about it some more.

            Imagine these methods become available in a future version of Qt:

            • QVariant& QStandardItem::dataRef(int role)
            • void* QVariant::internalPointer()

            These are the kinds of "extensions" that you wanted when you said "Increasing usage of references for non-value objects" right?

            With these functions, are you sure you can modify the data inside a QStandardItem without copying anything AND emit the required signal? Write some example code to try it.

            E Offline
            E Offline
            elfring
            wrote on 2 Oct 2018, 15:07 last edited by
            #23

            Imagine these methods become available in a future version of Qt:

            I guess that they can become useful for protected member functions.

            These are the kinds of "extensions" that you wanted when you said "Increasing usage of references for non-value objects" right?

            These suggestions can eventually fit to my imaginations. The mapping of (internal) data to custom information might need C++ function templates.

            …, are you sure you can modify the data inside a QStandardItem without copying anything AND emit the required signal?

            I propose to distinguish better between efficient data access and signal transmission for the discussed use cases.

            J 1 Reply Last reply 2 Oct 2018, 23:16
            0
            • E elfring
              2 Oct 2018, 09:23

              do you have any others in mind?

              Yes, of course.

              • Programming interfaces which return pointers can be encapsulated so that null pointer checks will be performed at fewer source code places.
              • Model adaptors
              • Occasional Qt object construction without default parameters
              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 2 Oct 2018, 15:10 last edited by kshegunov 10 Feb 2018, 15:12
              #24

              @elfring said in Increasing usage of references for non-value objects?:

              • Programming interfaces which return pointers can be encapsulated so that null pointer checks will be performed at fewer source code places.

              And factories to create those objects too, right? Sounds more like Java. There's no reason to throw abstractions over simple classes that don't need them. Factories for the sake of factories and interfaces for the sake of interfaces is what Java does, it's verbose and slow and gives you nothing in return. There's a factory here and there and an interface here and there in Qt, but where it is needed, not just for the sole purpose of implementing patterns. To finish that rant off - why do you want to force heap allocations onto me? I prefer and use the stack wherever possible as it's faster and safer, you now want me to new every single object I create?

              • Model adaptors

              To what end? Adapters for what exactly? You have proxy models, and models are (almost) perfectly matched to the views' interfaces, so what is that you want an adapter for? ... and you can always write your own if you need it to match your own class' interfaces.

              • Occasional Qt object construction without default parameters

              Practically all Qt classes allow for default constructors. As for the default parameters themselves - it's just an implementation detail that's moot here.

              If you have explicitly concrete examples of why any of the above is needed, I'm all ears, otherwise this is simply a theoretical debate with very little practical relevance.

              Read and abide by the Qt Code of Conduct

              E 1 Reply Last reply 2 Oct 2018, 15:40
              4
              • K kshegunov
                2 Oct 2018, 15:10

                @elfring said in Increasing usage of references for non-value objects?:

                • Programming interfaces which return pointers can be encapsulated so that null pointer checks will be performed at fewer source code places.

                And factories to create those objects too, right? Sounds more like Java. There's no reason to throw abstractions over simple classes that don't need them. Factories for the sake of factories and interfaces for the sake of interfaces is what Java does, it's verbose and slow and gives you nothing in return. There's a factory here and there and an interface here and there in Qt, but where it is needed, not just for the sole purpose of implementing patterns. To finish that rant off - why do you want to force heap allocations onto me? I prefer and use the stack wherever possible as it's faster and safer, you now want me to new every single object I create?

                • Model adaptors

                To what end? Adapters for what exactly? You have proxy models, and models are (almost) perfectly matched to the views' interfaces, so what is that you want an adapter for? ... and you can always write your own if you need it to match your own class' interfaces.

                • Occasional Qt object construction without default parameters

                Practically all Qt classes allow for default constructors. As for the default parameters themselves - it's just an implementation detail that's moot here.

                If you have explicitly concrete examples of why any of the above is needed, I'm all ears, otherwise this is simply a theoretical debate with very little practical relevance.

                E Offline
                E Offline
                elfring
                wrote on 2 Oct 2018, 15:40 last edited by
                #25

                …, you now want me to new every single object I create?

                No. - But a lot of objects are generated by this operator as usual.

                You have proxy models, …

                How do you think about a test case for the topic “Support for QStandardItem proxies?” then?

                If you have explicitly concrete examples of why any of the above is needed, I'm all ears, …

                Would you like to take another look at a feature request like “Support for object creation based on constructors with parameters without default values”?

                K 1 Reply Last reply 2 Oct 2018, 20:30
                0
                • E elfring
                  2 Oct 2018, 15:40

                  …, you now want me to new every single object I create?

                  No. - But a lot of objects are generated by this operator as usual.

                  You have proxy models, …

                  How do you think about a test case for the topic “Support for QStandardItem proxies?” then?

                  If you have explicitly concrete examples of why any of the above is needed, I'm all ears, …

                  Would you like to take another look at a feature request like “Support for object creation based on constructors with parameters without default values”?

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 2 Oct 2018, 20:30 last edited by
                  #26

                  @elfring said in Increasing usage of references for non-value objects?:

                  No.

                  Then don't.

                  • But a lot of objects are generated by this operator as usual.

                  I may usually drink coffee, but this doesn't mean I only drink coffee, does it?

                  How do you think about a test case for the topic “Support for QStandardItem proxies?” then?

                  Formally speaking the item delegates are already adapters, so I don't follow your point.

                  Would you like to take another look at a feature request like “Support for object creation based on constructors with parameters without default values”?

                  I have no idea why you want to force non-default-constructable objects to the designer. I see no gain in even trying to do such a thing, much less what would be the point of enforcing it ...

                  Read and abide by the Qt Code of Conduct

                  E 1 Reply Last reply 2 Oct 2018, 20:40
                  1
                  • K kshegunov
                    2 Oct 2018, 20:30

                    @elfring said in Increasing usage of references for non-value objects?:

                    No.

                    Then don't.

                    • But a lot of objects are generated by this operator as usual.

                    I may usually drink coffee, but this doesn't mean I only drink coffee, does it?

                    How do you think about a test case for the topic “Support for QStandardItem proxies?” then?

                    Formally speaking the item delegates are already adapters, so I don't follow your point.

                    Would you like to take another look at a feature request like “Support for object creation based on constructors with parameters without default values”?

                    I have no idea why you want to force non-default-constructable objects to the designer. I see no gain in even trying to do such a thing, much less what would be the point of enforcing it ...

                    E Offline
                    E Offline
                    elfring
                    wrote on 2 Oct 2018, 20:40 last edited by
                    #27

                    Formally speaking the item delegates are already adapters, so I don't follow your point.

                    Do you prefer to fiddle with delegates instead of adjusting data models by proxies (for simple displays)?

                    I have no idea why you want to force non-default-constructable objects to the designer.

                    Do you find any of the linked information helpful anyhow?

                    V 1 Reply Last reply 3 Oct 2018, 06:05
                    0
                    • E elfring
                      2 Oct 2018, 15:07

                      Imagine these methods become available in a future version of Qt:

                      I guess that they can become useful for protected member functions.

                      These are the kinds of "extensions" that you wanted when you said "Increasing usage of references for non-value objects" right?

                      These suggestions can eventually fit to my imaginations. The mapping of (internal) data to custom information might need C++ function templates.

                      …, are you sure you can modify the data inside a QStandardItem without copying anything AND emit the required signal?

                      I propose to distinguish better between efficient data access and signal transmission for the discussed use cases.

                      J Offline
                      J Offline
                      JKSH
                      Moderators
                      wrote on 2 Oct 2018, 23:16 last edited by JKSH 10 Feb 2018, 23:28
                      #28

                      @elfring said in Increasing usage of references for non-value objects?:

                      Imagine these methods become available in a future version of Qt:

                      I guess that they can become useful for protected member functions.

                      ...

                      These suggestions can eventually fit to my imaginations.

                      Question: Are these are the kinds of "extensions" that you wanted when you said "Increasing usage of references for non-value objects"? If not, then please write some example code to show us your proposal. Without this, it is very difficult to discuss things.

                      …, are you sure you can modify the data inside a QStandardItem without copying anything AND emit the required signal?

                      I propose to distinguish better between efficient data access and signal transmission for the discussed use cases.

                      You are asking for the API to be changed to increase efficiency, but you must also realize this change makes the API design less intuitive which increases the risk of errors. (see @VRonin's post: "Modifying the internal object from outside the model and then emitting the dataChanged manually is a hack and a breach of S.O.L.I.D" ) This is also considered premature optimization.

                      QStandardItemModel is a convenience class, so intuitive design is much more important than efficiency here.

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      1 Reply Last reply
                      3
                      • E elfring
                        2 Oct 2018, 20:40

                        Formally speaking the item delegates are already adapters, so I don't follow your point.

                        Do you prefer to fiddle with delegates instead of adjusting data models by proxies (for simple displays)?

                        I have no idea why you want to force non-default-constructable objects to the designer.

                        Do you find any of the linked information helpful anyhow?

                        V Offline
                        V Offline
                        VRonin
                        wrote on 3 Oct 2018, 06:05 last edited by
                        #29

                        @elfring said in Increasing usage of references for non-value objects?:

                        Do you prefer to fiddle with delegates instead of adjusting data models by proxies (for simple displays)?

                        1000 times yes

                        "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
                        • J JKSH
                          2 Oct 2018, 14:48

                          @elfring said in Increasing usage of references for non-value objects?:

                          how can you emit the "itemChanged()" signal?

                          I would use a simple function call for this purpose.
                          Are you looking for any other answer?

                          I need you to think about it some more.

                          Imagine these methods become available in a future version of Qt:

                          • QVariant& QStandardItem::dataRef(int role)
                          • void* QVariant::internalPointer()

                          These are the kinds of "extensions" that you wanted when you said "Increasing usage of references for non-value objects" right?

                          With these functions, are you sure you can modify the data inside a QStandardItem without copying anything AND emit the required signal? Write some example code to try it.

                          E Offline
                          E Offline
                          elfring
                          wrote on 3 Oct 2018, 15:27 last edited by
                          #30

                          Imagine these methods become available in a future version of Qt:

                          I suggest to take another look for a clarification try around the topic “Checking the API status for the variable “Private d” of the QVariant class”.

                          1 Reply Last reply
                          0

                          28/30

                          2 Oct 2018, 23:16

                          • Login

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