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. Checking the API status for the variable “Private d” of the QVariant class

Checking the API status for the variable “Private d” of the QVariant class

Scheduled Pinned Locked Moved Unsolved General and Desktop
apiqvariantprivatedocumentationevolution
31 Posts 5 Posters 7.7k 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 Offline
    E Offline
    elfring
    wrote on 3 Oct 2018, 13:10 last edited by
    #1

    I have noticed the following source code.

    …
    // ### Qt6: FIXME: Remove the special Q_CC_MSVC handling, it was introduced to maintain BC for QTBUG-41810 .
    #if !defined(Q_NO_TEMPLATE_FRIENDS) && !defined(Q_CC_MSVC)
        template<typename T>
        friend inline T qvariant_cast(const QVariant &);
        template<typename T> friend struct QtPrivate::QVariantValueHelper;
    protected:
    #else
    public:
    #endif
        Private d;
    …
    

    I have noticed also that the member variable “d” is not mentioned in the Qt documentation so far. So I get doubts if it can really belong to the public programming interface by this class.
    How will this software evolve further?

    R 1 Reply Last reply 3 Oct 2018, 13:18
    0
    • E elfring
      3 Oct 2018, 13:10

      I have noticed the following source code.

      …
      // ### Qt6: FIXME: Remove the special Q_CC_MSVC handling, it was introduced to maintain BC for QTBUG-41810 .
      #if !defined(Q_NO_TEMPLATE_FRIENDS) && !defined(Q_CC_MSVC)
          template<typename T>
          friend inline T qvariant_cast(const QVariant &);
          template<typename T> friend struct QtPrivate::QVariantValueHelper;
      protected:
      #else
      public:
      #endif
          Private d;
      …
      

      I have noticed also that the member variable “d” is not mentioned in the Qt documentation so far. So I get doubts if it can really belong to the public programming interface by this class.
      How will this software evolve further?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 3 Oct 2018, 13:18 last edited by
      #2

      @elfring
      the d-pointer is the private implementation of Qt classes and guarantee binary compatibility over Qt minor versions.
      I don't know when Q_NO_TEMPLATE_FRIENDS will really be defined so that the d-pointer becomes public.

      But anyway d-pointers are not meant to be accessed.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 3 Oct 2018, 13:21 last edited by
        #3

        d does not belong to the public interface so you don't have to worry

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        S 1 Reply Last reply 3 Oct 2018, 13:23
        3
        • C Christian Ehrlicher
          3 Oct 2018, 13:21

          d does not belong to the public interface so you don't have to worry

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 3 Oct 2018, 13:23 last edited by
          #4

          @Christian-Ehrlicher said in Checking the API status for the variable “Private d” of the QVariant class:

          d does not belong to the public interface so you don't have to worry

          Guys but take a look at the code - this is not the d pointer, it's and instance of Private struct, called d. Looks like it is indeed part of the public interface here.

          (Z(:^

          E 1 Reply Last reply 3 Oct 2018, 13:27
          1
          • S sierdzio
            3 Oct 2018, 13:23

            @Christian-Ehrlicher said in Checking the API status for the variable “Private d” of the QVariant class:

            d does not belong to the public interface so you don't have to worry

            Guys but take a look at the code - this is not the d pointer, it's and instance of Private struct, called d. Looks like it is indeed part of the public interface here.

            E Offline
            E Offline
            elfring
            wrote on 3 Oct 2018, 13:27 last edited by
            #5

            Looks like it is indeed part of the public interface here.

            Conditional compilation can eventually make this variable “protected”, can't it?

            S 1 Reply Last reply 3 Oct 2018, 13:30
            0
            • E elfring
              3 Oct 2018, 13:27

              Looks like it is indeed part of the public interface here.

              Conditional compilation can eventually make this variable “protected”, can't it?

              S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 3 Oct 2018, 13:30 last edited by
              #6

              @elfring said in Checking the API status for the variable “Private d” of the QVariant class:

              Looks like it is indeed part of the public interface here.

              Conditional compilation can eventually make this variable “protected”, can't it?

              Yes, but since it's not a pointer, it can affect memory layout => damage binary compatibility. Even if it is private. Some more info: https://stackoverflow.com/questions/7699259/how-does-adding-a-private-member-variable-break-c-abi-compatibility

              (Z(:^

              1 Reply Last reply
              1
              • V Offline
                V Offline
                VRonin
                wrote on 3 Oct 2018, 13:32 last edited by
                #7

                Q_NO_TEMPLATE_FRIENDS is only defined in old or unusual compilers, if you trust the comment (i.e. the Q_CC_MSVC only exist for binary compatibility but it should be removed) I'd say the base case is for d to be protected

                "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 3 Oct 2018, 13:47
                3
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 3 Oct 2018, 13:45 last edited by
                  #8

                  And you can be sure this will not change inbetween a Qt X release cycle. It's a 32+64 bit struct which was adjusted to match the requirements. Noone will ever touch this in a form that the size will change.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1
                  • V VRonin
                    3 Oct 2018, 13:32

                    Q_NO_TEMPLATE_FRIENDS is only defined in old or unusual compilers, if you trust the comment (i.e. the Q_CC_MSVC only exist for binary compatibility but it should be removed) I'd say the base case is for d to be protected

                    E Offline
                    E Offline
                    elfring
                    wrote on 3 Oct 2018, 13:47 last edited by
                    #9

                    I'd say the base case is for d to be protected

                    Would you like to encapsulate accesses for the member variable “d” (of the class “QVariant”) by any other function?

                    V 1 Reply Last reply 3 Oct 2018, 13:55
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 3 Oct 2018, 13:52 last edited by
                      #10

                      d is protected so no other function will get access to this variable and there is also no need for it. What do you want to achieve?

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      E 1 Reply Last reply 3 Oct 2018, 14:26
                      1
                      • E elfring
                        3 Oct 2018, 13:47

                        I'd say the base case is for d to be protected

                        Would you like to encapsulate accesses for the member variable “d” (of the class “QVariant”) by any other function?

                        V Offline
                        V Offline
                        VRonin
                        wrote on 3 Oct 2018, 13:55 last edited by VRonin 10 Mar 2018, 14:01
                        #11

                        @elfring said in Checking the API status for the variable “Private d” of the QVariant class:

                        Would you like to encapsulate accesses for the member variable “d” (of the class “QVariant”) by any other function?

                        it is already [kind of]* exposed by data() but as you see it's explicitly set to return a const void*.

                        *if you don't save basic types in the variant then it is exposed

                        "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
                        • C Christian Ehrlicher
                          3 Oct 2018, 13:52

                          d is protected so no other function will get access to this variable and there is also no need for it. What do you want to achieve?

                          E Offline
                          E Offline
                          elfring
                          wrote on 3 Oct 2018, 14:26 last edited by
                          #12

                          What do you want to achieve?

                          The mentioned access specifiers will influence possible software extensions around classes like “QVariant”.

                          • I would like to get safe access to the members in the data structure “QVariant::Private”.
                          • Would you like to support in-place modification for referenced objects then?
                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 3 Oct 2018, 14:30 last edited by Christian Ehrlicher 10 Mar 2018, 14:34
                            #13

                            You will never get any safe access to QVariant::Private - it's a private class and therefore can change any time. And no I don't need in-place modifications (this was discussed on the mailing list some weeks ago).

                            https://lists.qt-project.org/pipermail/interest/2018-June/030216.html

                            If you want in-place modifications then store a pointer in QVariant so you can modify the data without accessing the QVariant.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            E 2 Replies Last reply 3 Oct 2018, 15:02
                            3
                            • C Christian Ehrlicher
                              3 Oct 2018, 14:30

                              You will never get any safe access to QVariant::Private - it's a private class and therefore can change any time. And no I don't need in-place modifications (this was discussed on the mailing list some weeks ago).

                              https://lists.qt-project.org/pipermail/interest/2018-June/030216.html

                              If you want in-place modifications then store a pointer in QVariant so you can modify the data without accessing the QVariant.

                              E Offline
                              E Offline
                              elfring
                              wrote on 3 Oct 2018, 15:02 last edited by
                              #14

                              it's a private class

                              • Please take another look.
                              • The class declaration is using the access specifier “public” for this data structure so far, doesn't it?

                              this was discussed on the mailing list some weeks ago

                              Thanks for your link of the discussion topic “Why no T& QVariant::value()?”.

                              If you want in-place modifications then store a pointer in QVariant …

                              I became interested once more to perform some data processing for contents (which could be provided over variables like “QObject *o” and “PrivateShared *shared”) without extra copies.

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                VRonin
                                wrote on 4 Oct 2018, 07:42 last edited by
                                #15

                                You are looking for an unnecessary hack to solve a very simple problem.
                                If all the classes you have stored in a QVariant are implicitly shared* and the members of those classes are also all implicitly shared* and so on down the object tree, then your get-modify-set is already as efficient as you can get short of memcpy. If you want I can explain in detail why if it's not clear.

                                ' * or fundamental types

                                "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 4 Oct 2018, 08:20
                                2
                                • C Christian Ehrlicher
                                  3 Oct 2018, 14:30

                                  You will never get any safe access to QVariant::Private - it's a private class and therefore can change any time. And no I don't need in-place modifications (this was discussed on the mailing list some weeks ago).

                                  https://lists.qt-project.org/pipermail/interest/2018-June/030216.html

                                  If you want in-place modifications then store a pointer in QVariant so you can modify the data without accessing the QVariant.

                                  E Offline
                                  E Offline
                                  elfring
                                  wrote on 4 Oct 2018, 08:05 last edited by
                                  #16

                                  You will never get any safe access to QVariant::Private -

                                  I suggest to reconsider this information. - I guess that we got different expectations for the “safety” of such data structures.

                                  it's a private class

                                  The privacy concerns can vary also if you would like to implement possibly useful functionality for this class.

                                  and therefore can change any time.

                                  This aspect is reasonable for software evolution in general. I am curious on how change acceptance (or resistance?) will evolve here.

                                  And no I don't need in-place modifications

                                  Do other Qt users and software developers would like to apply this technique?

                                  If you want in-place modifications then store a pointer in QVariant so you can modify the data without accessing the QVariant.

                                  • This is another useful software design approach. But these pointers should refer to valid data.
                                  • This class can be treated as a container for a single item (with a varying internal data type). You would occasionally prefer direct write access to the contained element.
                                    I guess that I am looking again for Qt support of an operation which became standardised as “std::get”.
                                  V 1 Reply Last reply 4 Oct 2018, 08:49
                                  0
                                  • V VRonin
                                    4 Oct 2018, 07:42

                                    You are looking for an unnecessary hack to solve a very simple problem.
                                    If all the classes you have stored in a QVariant are implicitly shared* and the members of those classes are also all implicitly shared* and so on down the object tree, then your get-modify-set is already as efficient as you can get short of memcpy. If you want I can explain in detail why if it's not clear.

                                    ' * or fundamental types

                                    E Offline
                                    E Offline
                                    elfring
                                    wrote on 4 Oct 2018, 08:20 last edited by
                                    #17

                                    You are looking for an unnecessary hack to solve a very simple problem.

                                    It can take a while to get acceptance for another useful programming interface, can't it?

                                    1 Reply Last reply
                                    0
                                    • E elfring
                                      4 Oct 2018, 08:05

                                      You will never get any safe access to QVariant::Private -

                                      I suggest to reconsider this information. - I guess that we got different expectations for the “safety” of such data structures.

                                      it's a private class

                                      The privacy concerns can vary also if you would like to implement possibly useful functionality for this class.

                                      and therefore can change any time.

                                      This aspect is reasonable for software evolution in general. I am curious on how change acceptance (or resistance?) will evolve here.

                                      And no I don't need in-place modifications

                                      Do other Qt users and software developers would like to apply this technique?

                                      If you want in-place modifications then store a pointer in QVariant so you can modify the data without accessing the QVariant.

                                      • This is another useful software design approach. But these pointers should refer to valid data.
                                      • This class can be treated as a container for a single item (with a varying internal data type). You would occasionally prefer direct write access to the contained element.
                                        I guess that I am looking again for Qt support of an operation which became standardised as “std::get”.
                                      V Offline
                                      V Offline
                                      VRonin
                                      wrote on 4 Oct 2018, 08:49 last edited by
                                      #18

                                      @elfring said in Checking the API status for the variable “Private d” of the QVariant class:

                                      You would occasionally prefer direct write access to the contained element.

                                      My point is exactly that implicit sharing removes this need

                                      It can take a while to get acceptance for another useful programming interface, can't it?

                                      And it can take even longer if it's not necessary. Move constructor/assignments are another great example of a feature introduced in the standard that is basically useless when dealing with implicitly shared classes as they do it better and seamlessly.

                                      "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 4 Oct 2018, 09:11
                                      1
                                      • V VRonin
                                        4 Oct 2018, 08:49

                                        @elfring said in Checking the API status for the variable “Private d” of the QVariant class:

                                        You would occasionally prefer direct write access to the contained element.

                                        My point is exactly that implicit sharing removes this need

                                        It can take a while to get acceptance for another useful programming interface, can't it?

                                        And it can take even longer if it's not necessary. Move constructor/assignments are another great example of a feature introduced in the standard that is basically useless when dealing with implicitly shared classes as they do it better and seamlessly.

                                        E Offline
                                        E Offline
                                        elfring
                                        wrote on 4 Oct 2018, 09:11 last edited by
                                        #19

                                        My point is exactly that implicit sharing removes this need

                                        This technique depends on the management of object reference counters which can be useful functionality and can trigger related software development challenges.

                                        And it can take even longer if it's not necessary.

                                        Do you care for improvements around generic data processing algorithms?

                                        V 1 Reply Last reply 4 Oct 2018, 09:39
                                        0
                                        • E elfring
                                          4 Oct 2018, 09:11

                                          My point is exactly that implicit sharing removes this need

                                          This technique depends on the management of object reference counters which can be useful functionality and can trigger related software development challenges.

                                          And it can take even longer if it's not necessary.

                                          Do you care for improvements around generic data processing algorithms?

                                          V Offline
                                          V Offline
                                          VRonin
                                          wrote on 4 Oct 2018, 09:39 last edited by
                                          #20

                                          @elfring said in Checking the API status for the variable “Private d” of the QVariant class:

                                          This technique depends on the management of object reference counters

                                          Are we complaining about loss of performance due to an additional integer increment and decrement?

                                          Do you care for improvements around generic data processing algorithms?

                                          Not if they interfere heavily with my objects functionality isolation.


                                          Can I ask, really, what is causing your aversion to how QVariant works? The only scenario I'd imagine is if you are developing microsecond-critical applications (like automatic stock trading) but you mention you are using QStandardItemModel and the inefficiencies inside that model implementation dwarf any moot point about optimising the editing of a QVariant

                                          "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 4 Oct 2018, 09:55
                                          4

                                          1/31

                                          3 Oct 2018, 13:10

                                          • Login

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