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. C++ : call to temporary is a no-op
Forum Updated to NodeBB v4.3 + New Features

C++ : call to temporary is a no-op

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 5 Posters 2.5k Views 3 Watching
  • 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.
  • MasterQM MasterQ

    Hello,

    I have a class derived from QSqlRecord. Trying to write a setter for a field I get the mentioned message.

    But why is field here temporary?

    class D:QSqlRecord{
    public:
        void setId(int id){ field(0).setValue(id);}
    }
    

    I have to write

    void setId(int id){
        auto f = field(0);
        f.setValue(id);
        replace(0, f);
    }
    

    Is it really necessary to create a copy, modify it and to replace the original one with it? I don't want to alter the field object but only to call its setValue method.

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @MasterQ said in C++ : call to temporary is a no-op:

    I don't want to alter the field object but only to call its setValue method.

    Then you have a conceptual problem.

    By definition, a setter modifies an object.

    Qt has to stay free or it will die.

    MasterQM 1 Reply Last reply
    0
    • aha_1980A aha_1980

      @MasterQ said in C++ : call to temporary is a no-op:

      I don't want to alter the field object but only to call its setValue method.

      Then you have a conceptual problem.

      By definition, a setter modifies an object.

      MasterQM Offline
      MasterQM Offline
      MasterQ
      wrote on last edited by
      #3

      @aha_1980 said in C++ : call to temporary is a no-op:

      @MasterQ said in C++ : call to temporary is a no-op:

      I don't want to alter the field object but only to call its setValue method.

      Then you have a conceptual problem.

      really? For me it is a difference between altering an object instance and altering the content of an object (instance).

      A setter is modifying the content of an instance of an object, not the instance itself.

      But that is another topic.

      Pl45m4P 1 Reply Last reply
      0
      • aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @MasterQ: Then back to topic: field(0) returns a copy, so calling field(0).setValue(id) modifies the temporary copy.

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • MasterQM Offline
          MasterQM Offline
          MasterQ
          wrote on last edited by
          #5

          This is by concept of Qt I think. I am wondering why they have decided to return a copy and not a reference to the original field.

          On a number of topics, C++ tutorials say it is mostly better to return references instead of copies to reduce the number of copy tasks. Quite all methods with QStrings as parameter are asking for references not copies.

          Is there a reasonable explanation why this here is different?

          "Love it or change it" - I don't can/want to change it. But I want to understand why this solution was choosen.

          1 Reply Last reply
          0
          • MasterQM MasterQ

            @aha_1980 said in C++ : call to temporary is a no-op:

            @MasterQ said in C++ : call to temporary is a no-op:

            I don't want to alter the field object but only to call its setValue method.

            Then you have a conceptual problem.

            really? For me it is a difference between altering an object instance and altering the content of an object (instance).

            A setter is modifying the content of an instance of an object, not the instance itself.

            But that is another topic.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #6

            @MasterQ said in C++ : call to temporary is a no-op:

            For me it is a difference between altering an object instance and altering the content of an object (instance).

            Think about what defines an "object"...

            Say you have an object:

            Blubb blubb
            and a pointer to it:
            Blubb *pBlubb = &blubb

            In memory:
            0x000000 - 0x000004

            |   x   |   x  |   x   |   x   |   x   |   
            

            Blubb *pBlubb could look like this:

               ptr = 0x000000                     (sizeOfBlubb)
                |                                  |
            |   x   |   x  |   x   |   x   |   x   |   
            

            So if you modify the content of your Blubb in memory, either via pointer access or change the object itself:

            |   x   |   x  |   y   |   y   |   y   |   
            

            the "content" = "instance" changes (what bytes are written to the memory).

            What does not change, is the pointer pBlubb to your Blubb object.... it still points where Blubb starts in memory...

            This is just a simplification, there's much more going on...

            I don't understand what you want to tell us with the sentence above ;-)

            (Off-topic)
            Edit:
            Knowing this also helps to understand the difference between:

            [ 0 ] Blubb *pBlubb;
            [ 1 ] const Blubb *pBlubb;
            [ 2 ] Blubb *pBlubb const;
            [ 3 ] Blubb *const pBlubb;
            [ 4 ] const Blubb *pBlubb const;
            

            Ask yourself, what can be changed from [0] - [4].

            @MasterQ said in C++ : call to temporary is a no-op:

            This is by concept of Qt I think. I am wondering why they have decided to return a copy and not a reference to the original field.

            Because QSqlField is not a QObject...
            It's a registered QMetaObject kind of "struct"....
            and, as the documentation states, implicitly-shared... so even "copies" share the same memory until you detach them manually or by modifying one of them.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            Pl45m4P 1 Reply Last reply
            1
            • MasterQM MasterQ

              Hello,

              I have a class derived from QSqlRecord. Trying to write a setter for a field I get the mentioned message.

              But why is field here temporary?

              class D:QSqlRecord{
              public:
                  void setId(int id){ field(0).setValue(id);}
              }
              

              I have to write

              void setId(int id){
                  auto f = field(0);
                  f.setValue(id);
                  replace(0, f);
              }
              

              Is it really necessary to create a copy, modify it and to replace the original one with it? I don't want to alter the field object but only to call its setValue method.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #7

              @MasterQ said in C++ : call to temporary is a no-op:

              void setId(int id){ field(0).setValue(id);}

              Are you aware that (to change the value in a QSqlRecord) you are intended to write:

              setValue(0, id);
              // or
              setValue("id", id);
              

              ? https://doc.qt.io/qt-6/qsqlrecord.html#setValue

              MasterQM 1 Reply Last reply
              0
              • MasterQM Offline
                MasterQM Offline
                MasterQ
                wrote on last edited by
                #8

                I am not a professional and maybe my wording is not correct by 100%.

                I know what you want to say.

                Back to the topic.

                @Pl45m4 said in C++ : call to temporary is a no-op:

                Because QSqlField is not a QObject...
                It's a registered QMetaObject kind of "struct"....
                and, as the documentation states, implicitly-shared... so even "copies" share the same memory until you detach them manually or by modifying one of them.

                from my documentation:

                The QSqlField **class** manipulates the fields in SQL database tables and views.
                and

                A QSqlField **object** can provide some meta-data about the field, ...

                meta-data? sounds like QObject. But maybe not by 100%? If I remember right, all Qt stuff is derived from QObject.

                and from source code

                class Q_SQL_EXPORT QSqlField
                {
                ...
                

                I am a little more confused now.

                Nevertheless, it is as it is. I now know about and that's fine.

                BTW: Is there a tool to show the full hierarchical tree of Qt-Classes?

                Sorry if I am bothering you but I am always trying to dig to the ground of things I don't understand.

                Pl45m4P 1 Reply Last reply
                0
                • JonBJ JonB

                  @MasterQ said in C++ : call to temporary is a no-op:

                  void setId(int id){ field(0).setValue(id);}

                  Are you aware that (to change the value in a QSqlRecord) you are intended to write:

                  setValue(0, id);
                  // or
                  setValue("id", id);
                  

                  ? https://doc.qt.io/qt-6/qsqlrecord.html#setValue

                  MasterQM Offline
                  MasterQM Offline
                  MasterQ
                  wrote on last edited by MasterQ
                  #9

                  @JonB said in C++ : call to temporary is a no-op:

                  Are you aware that (to change the value in a QSqlRecord) you are intended to write:
                  ...

                  Yes!

                  full citation:

                     class AccountTransactionsTagEntity : public QSqlRecord {
                          //Q_OBJECT
                  
                      public:
                           AccountTransactionsTagEntity();
                           AccountTransactionsTagEntity(AccountTransactionsTagEntity const &entity);
                           AccountTransactionsTagEntity(AccountTransactionsTagEntity const &&entity) noexcept;
                          explicit AccountTransactionsTagEntity(QSqlRecord const &record);
                          explicit AccountTransactionsTagEntity(QSqlRecord const &&record);
                  
                          [[nodiscard]] int id() const { return field(Id).value().toInt(); }
                          [[nodiscard]] int categorieId() const { return field(CategoryId).value().toInt(); }
                          [[nodiscard]] QString pattern() const { return field(Pattern).value().toString(); }
                          [[nodiscard]] QString description() const { return field(Description).value().toString(); }
                  
                          void setId(int id) {
                              auto f = field(Id);
                              f.setValue(id);
                              replace(Id, f);
                          }
                          //
                          // void setCategorieId(int id) { field(CategoryId).setValue(id); }
                          // void setPattern(QString pattern) { field(Pattern).setValue(pattern); }
                          // void setDescription() { field(Description).value().toString(); }
                  
                  
                          enum Datafield {
                              Id = 0,
                              CategoryId,
                              Pattern,
                              Description
                          };
                      };
                  
                  JonBJ 2 Replies Last reply
                  0
                  • MasterQM MasterQ

                    @JonB said in C++ : call to temporary is a no-op:

                    Are you aware that (to change the value in a QSqlRecord) you are intended to write:
                    ...

                    Yes!

                    full citation:

                       class AccountTransactionsTagEntity : public QSqlRecord {
                            //Q_OBJECT
                    
                        public:
                             AccountTransactionsTagEntity();
                             AccountTransactionsTagEntity(AccountTransactionsTagEntity const &entity);
                             AccountTransactionsTagEntity(AccountTransactionsTagEntity const &&entity) noexcept;
                            explicit AccountTransactionsTagEntity(QSqlRecord const &record);
                            explicit AccountTransactionsTagEntity(QSqlRecord const &&record);
                    
                            [[nodiscard]] int id() const { return field(Id).value().toInt(); }
                            [[nodiscard]] int categorieId() const { return field(CategoryId).value().toInt(); }
                            [[nodiscard]] QString pattern() const { return field(Pattern).value().toString(); }
                            [[nodiscard]] QString description() const { return field(Description).value().toString(); }
                    
                            void setId(int id) {
                                auto f = field(Id);
                                f.setValue(id);
                                replace(Id, f);
                            }
                            //
                            // void setCategorieId(int id) { field(CategoryId).setValue(id); }
                            // void setPattern(QString pattern) { field(Pattern).setValue(pattern); }
                            // void setDescription() { field(Description).value().toString(); }
                    
                    
                            enum Datafield {
                                Id = 0,
                                CategoryId,
                                Pattern,
                                Description
                            };
                        };
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #10

                    @MasterQ
                    So that is what you should do! There are no "temporaries" or "copying of ..." if you do it that way.

                    If I remember right, all Qt stuff is derived from QObject.

                    Not at all. And QSqlField is not a QObject. Nor are QString, QList, .... The docs would always tell you what a class inherits, QObject or otherwise, right at the start of the page.

                    1 Reply Last reply
                    1
                    • MasterQM MasterQ

                      I am not a professional and maybe my wording is not correct by 100%.

                      I know what you want to say.

                      Back to the topic.

                      @Pl45m4 said in C++ : call to temporary is a no-op:

                      Because QSqlField is not a QObject...
                      It's a registered QMetaObject kind of "struct"....
                      and, as the documentation states, implicitly-shared... so even "copies" share the same memory until you detach them manually or by modifying one of them.

                      from my documentation:

                      The QSqlField **class** manipulates the fields in SQL database tables and views.
                      and

                      A QSqlField **object** can provide some meta-data about the field, ...

                      meta-data? sounds like QObject. But maybe not by 100%? If I remember right, all Qt stuff is derived from QObject.

                      and from source code

                      class Q_SQL_EXPORT QSqlField
                      {
                      ...
                      

                      I am a little more confused now.

                      Nevertheless, it is as it is. I now know about and that's fine.

                      BTW: Is there a tool to show the full hierarchical tree of Qt-Classes?

                      Sorry if I am bothering you but I am always trying to dig to the ground of things I don't understand.

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by Pl45m4
                      #11

                      @MasterQ said in C++ : call to temporary is a no-op:

                      from my documentation:

                      The QSqlField class manipulates the fields in SQL database tables and views.
                      and

                      A QSqlField object can provide some meta-data about the field, ...

                      meta-data? sounds like QObject. But maybe not by 100%? If I remember right, all Qt stuff is derived from QObject.

                      So you must have a different documentation on Qt :)

                      • https://doc.qt.io/qt-6/qsqlfield.html

                      If QSqlField would be a QObject, its inheritance hierarchy would be listed below the qmake row in that table at the start of the page.

                      @MasterQ said in C++ : call to temporary is a no-op:

                      BTW: Is there a tool to show the full hierarchical tree of Qt-Classes?

                      There's a listing of all classes and all modules, but unfortunately without any tree-like relation between them.
                      As @JonB said and I mentioned above, you can check the "header" in the official documentation pages of any Q.... class of interest and you will see the direct inherited and inheriting classes... you can follow that route by clicking them :)


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      MasterQM 1 Reply Last reply
                      0
                      • Pl45m4P Pl45m4

                        @MasterQ said in C++ : call to temporary is a no-op:

                        from my documentation:

                        The QSqlField class manipulates the fields in SQL database tables and views.
                        and

                        A QSqlField object can provide some meta-data about the field, ...

                        meta-data? sounds like QObject. But maybe not by 100%? If I remember right, all Qt stuff is derived from QObject.

                        So you must have a different documentation on Qt :)

                        • https://doc.qt.io/qt-6/qsqlfield.html

                        If QSqlField would be a QObject, its inheritance hierarchy would be listed below the qmake row in that table at the start of the page.

                        @MasterQ said in C++ : call to temporary is a no-op:

                        BTW: Is there a tool to show the full hierarchical tree of Qt-Classes?

                        There's a listing of all classes and all modules, but unfortunately without any tree-like relation between them.
                        As @JonB said and I mentioned above, you can check the "header" in the official documentation pages of any Q.... class of interest and you will see the direct inherited and inheriting classes... you can follow that route by clicking them :)

                        MasterQM Offline
                        MasterQM Offline
                        MasterQ
                        wrote on last edited by
                        #12

                        @Pl45m4 said in C++ : call to temporary is a no-op:

                        So you must have a different documentation on Qt :)

                        • https://doc.qt.io/qt-6/qsqlfield.html

                        Noooo! ;-)

                        c77063b1-bfd7-42dc-b37b-fae476560c65-image.png

                        f2d3ac04-b010-4e95-84d1-6518c015bfd4-image.png

                        If QSqlField would be a QObject, its inheritance hierarchy would be listed below the qmake row in that table at the start of the page.

                        I got it! That explains some other issues I had.

                        @MasterQ said in C++ : call to temporary is a no-op:

                        BTW: Is there a tool to show the full hierarchical tree of Qt-Classes?

                        ... you can follow that route by clicking them :)

                        I expected that ... unfortunately! :-(

                        Thanks.

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          Object and QObject are two different things. An object is an instance of a class (c++ basics) , a QObject is a Qt (base) class.

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

                          MasterQM 1 Reply Last reply
                          1
                          • MasterQM MasterQ

                            @JonB said in C++ : call to temporary is a no-op:

                            Are you aware that (to change the value in a QSqlRecord) you are intended to write:
                            ...

                            Yes!

                            full citation:

                               class AccountTransactionsTagEntity : public QSqlRecord {
                                    //Q_OBJECT
                            
                                public:
                                     AccountTransactionsTagEntity();
                                     AccountTransactionsTagEntity(AccountTransactionsTagEntity const &entity);
                                     AccountTransactionsTagEntity(AccountTransactionsTagEntity const &&entity) noexcept;
                                    explicit AccountTransactionsTagEntity(QSqlRecord const &record);
                                    explicit AccountTransactionsTagEntity(QSqlRecord const &&record);
                            
                                    [[nodiscard]] int id() const { return field(Id).value().toInt(); }
                                    [[nodiscard]] int categorieId() const { return field(CategoryId).value().toInt(); }
                                    [[nodiscard]] QString pattern() const { return field(Pattern).value().toString(); }
                                    [[nodiscard]] QString description() const { return field(Description).value().toString(); }
                            
                                    void setId(int id) {
                                        auto f = field(Id);
                                        f.setValue(id);
                                        replace(Id, f);
                                    }
                                    //
                                    // void setCategorieId(int id) { field(CategoryId).setValue(id); }
                                    // void setPattern(QString pattern) { field(Pattern).setValue(pattern); }
                                    // void setDescription() { field(Description).value().toString(); }
                            
                            
                                    enum Datafield {
                                        Id = 0,
                                        CategoryId,
                                        Pattern,
                                        Description
                                    };
                                };
                            
                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #14

                            @MasterQ said in C++ : call to temporary is a no-op:

                            full citation:

                            You wrote/added this after I wrote about using QSqlRecord::setValue(). I am unclear: are you aware that what you show in your "full citation" is not the (best) way to read or write a value in a QSqlRecord (and you should change)? Just checking.

                            While on the topic you mentioned "isn't everything in Qt a QObject" and you are investigating Qt, have you read Implicit Sharing? The list on that page includes QSqlField (and QSqlRecord). It is worth understanding this concept in Qt code too. No QObjects are implicitly shared.

                            1 Reply Last reply
                            1
                            • Christian EhrlicherC Christian Ehrlicher

                              Object and QObject are two different things. An object is an instance of a class (c++ basics) , a QObject is a Qt (base) class.

                              MasterQM Offline
                              MasterQM Offline
                              MasterQ
                              wrote on last edited by
                              #15

                              @Christian-Ehrlicher said in C++ : call to temporary is a no-op:

                              Object and QObject are two different things. An object is an instance of a class (c++ basics) , a QObject is a Qt (base) class.

                              I never claimed object and QObject are the same thing. I mentioned the doc since @Pl45m4 said QSqlField would be a struct.

                              @JonB said in C++ : call to temporary is a no-op:

                              @MasterQ said in C++ : call to temporary is a no-op:

                              full citation:

                              You wrote/added this after I wrote about using QSqlRecord::setValue(). I am unclear: are you aware that what you show in your "full citation" is not the (best) way to read or write a value in a QSqlRecord (and you should change)? Just checking.

                              I am not sure if I got you. You mean the version to address the field by name is better as to address by index, right? Since I have full controll about the structure of the database I also have full control of the sequence of the fields. I agree that by name is a safer way to do it. Maybe I will change in future. At the moment there are other issues with higher priority.

                              While on the topic you mentioned "isn't everything in Qt a QObject" and you are investigating Qt, have you read Implicit Sharing?

                              No, I was not aware of that topic. Thanks for pointing to.

                              MasterQM Christian EhrlicherC JonBJ 3 Replies Last reply
                              0
                              • Pl45m4P Pl45m4

                                @MasterQ said in C++ : call to temporary is a no-op:

                                For me it is a difference between altering an object instance and altering the content of an object (instance).

                                Think about what defines an "object"...

                                Say you have an object:

                                Blubb blubb
                                and a pointer to it:
                                Blubb *pBlubb = &blubb

                                In memory:
                                0x000000 - 0x000004

                                |   x   |   x  |   x   |   x   |   x   |   
                                

                                Blubb *pBlubb could look like this:

                                   ptr = 0x000000                     (sizeOfBlubb)
                                    |                                  |
                                |   x   |   x  |   x   |   x   |   x   |   
                                

                                So if you modify the content of your Blubb in memory, either via pointer access or change the object itself:

                                |   x   |   x  |   y   |   y   |   y   |   
                                

                                the "content" = "instance" changes (what bytes are written to the memory).

                                What does not change, is the pointer pBlubb to your Blubb object.... it still points where Blubb starts in memory...

                                This is just a simplification, there's much more going on...

                                I don't understand what you want to tell us with the sentence above ;-)

                                (Off-topic)
                                Edit:
                                Knowing this also helps to understand the difference between:

                                [ 0 ] Blubb *pBlubb;
                                [ 1 ] const Blubb *pBlubb;
                                [ 2 ] Blubb *pBlubb const;
                                [ 3 ] Blubb *const pBlubb;
                                [ 4 ] const Blubb *pBlubb const;
                                

                                Ask yourself, what can be changed from [0] - [4].

                                @MasterQ said in C++ : call to temporary is a no-op:

                                This is by concept of Qt I think. I am wondering why they have decided to return a copy and not a reference to the original field.

                                Because QSqlField is not a QObject...
                                It's a registered QMetaObject kind of "struct"....
                                and, as the documentation states, implicitly-shared... so even "copies" share the same memory until you detach them manually or by modifying one of them.

                                Pl45m4P Offline
                                Pl45m4P Offline
                                Pl45m4
                                wrote on last edited by Pl45m4
                                #16

                                @MasterQ said in C++ : call to temporary is a no-op:

                                No, I was not aware of that topic. Thanks for pointing to.

                                I explained here already:

                                @Pl45m4 said in C++ : call to temporary is a no-op:

                                @MasterQ said in C++ : call to temporary is a no-op:

                                This is by concept of Qt I think. I am wondering why they have decided to return a copy and not a reference to the original field.

                                Because QSqlField is not a QObject...
                                It's a registered QMetaObject kind of "struct"....
                                and, as the documentation states, implicitly-shared... so even "copies" share the same memory until you detach them manually or by modifying one of them.

                                To sum this up:

                                QSqlField is just a data struct, but registered in the meta object system (still not a QObject).
                                It contains the column data of a database table (or of the current view on it).
                                It is implicitly-shared, which means, for 5000 copies of the same record it does not copy the data 5000 times...
                                Even though they are copies, they share the same data in memory, which means, they are the same until you change something...
                                Then the modified field detaches and all data is copied, separating the modified field from the others and making it unique.
                                In memory (your "objects"), you would have 4999 objects which share one memory and for the detached object the data is copied to a new address.

                                And as @aha_1980 said in C++ : call to temporary is a no-op:

                                Then back to topic: field(0) returns a copy, so calling field(0).setValue(id) modifies the temporary copy.

                                If I'm not wrong, setValue(id) will obviously modify/change the field... which causes the detachment... making a new, temporary field :)


                                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                ~E. W. Dijkstra

                                1 Reply Last reply
                                0
                                • MasterQM Offline
                                  MasterQM Offline
                                  MasterQ
                                  wrote on last edited by
                                  #17

                                  implicit sharing ... read ... understood ... check!

                                  I now also know, what this suspicious d pointer is.

                                  Pl45m4P 1 Reply Last reply
                                  0
                                  • MasterQM MasterQ

                                    @Christian-Ehrlicher said in C++ : call to temporary is a no-op:

                                    Object and QObject are two different things. An object is an instance of a class (c++ basics) , a QObject is a Qt (base) class.

                                    I never claimed object and QObject are the same thing. I mentioned the doc since @Pl45m4 said QSqlField would be a struct.

                                    @JonB said in C++ : call to temporary is a no-op:

                                    @MasterQ said in C++ : call to temporary is a no-op:

                                    full citation:

                                    You wrote/added this after I wrote about using QSqlRecord::setValue(). I am unclear: are you aware that what you show in your "full citation" is not the (best) way to read or write a value in a QSqlRecord (and you should change)? Just checking.

                                    I am not sure if I got you. You mean the version to address the field by name is better as to address by index, right? Since I have full controll about the structure of the database I also have full control of the sequence of the fields. I agree that by name is a safer way to do it. Maybe I will change in future. At the moment there are other issues with higher priority.

                                    While on the topic you mentioned "isn't everything in Qt a QObject" and you are investigating Qt, have you read Implicit Sharing?

                                    No, I was not aware of that topic. Thanks for pointing to.

                                    MasterQM Offline
                                    MasterQM Offline
                                    MasterQ
                                    wrote on last edited by MasterQ
                                    #18

                                    @Pl45m4 said in C++ : call to temporary is a no-op:

                                    @MasterQ said in C++ : call to temporary is a no-op:

                                    No, I was not aware of that topic. Thanks for pointing to.

                                    I explained here already:

                                    Because QSqlField is not a QObject...
                                    It's a registered QMetaObject kind of "struct"....
                                    and, as the documentation states, implicitly-shared... so even "copies" share the same memory until you detach them manually or by modifying one of them.

                                    This was misleading, sorry. I thought you were talking about the QSqlField documentation. But you meant the implicit shared documentation?

                                    In the documenation to QSqlField implicit sharing is not mentioned.

                                    If I'm not wrong, setValue(id) will obviously modify/change the field...

                                    Yes, you are right! ;-)

                                    1 Reply Last reply
                                    0
                                    • MasterQM MasterQ

                                      implicit sharing ... read ... understood ... check!

                                      I now also know, what this suspicious d pointer is.

                                      Pl45m4P Offline
                                      Pl45m4P Offline
                                      Pl45m4
                                      wrote on last edited by Pl45m4
                                      #19

                                      @MasterQ said in C++ : call to temporary is a no-op:

                                      I now also know, what this suspicious d pointer is.

                                      Haha we shouldn't start to discuss Qt implementation details and strategies here, as the topic is quite a mess already and confusing for future readers :)
                                      The d- and q-pointers have nothing to do with anything here and are a whole new story :)
                                      They are a product of how Qt's internal classes are organized and belong to the pIMPL idiom.

                                      @MasterQ said in C++ : call to temporary is a no-op:

                                      In the documenation to QSqlField implicit sharing is not mentioned.

                                      But it is mentioned that QSqlRecord and QSqlField are implicitly shared
                                      Btw: many classes contain that hint... if you know, you know.
                                      And if you read it once, in the future you know right away what you are dealing with :)

                                      QSqlField is part of Database Classes and Implicitly Shared Classes.
                                      ( https://doc.qt.io/qt-6/qsqlfield.html )


                                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                      ~E. W. Dijkstra

                                      1 Reply Last reply
                                      0
                                      • MasterQM Offline
                                        MasterQM Offline
                                        MasterQ
                                        wrote on last edited by
                                        #20

                                        damn complexity

                                        1 Reply Last reply
                                        0
                                        • MasterQM MasterQ

                                          @Christian-Ehrlicher said in C++ : call to temporary is a no-op:

                                          Object and QObject are two different things. An object is an instance of a class (c++ basics) , a QObject is a Qt (base) class.

                                          I never claimed object and QObject are the same thing. I mentioned the doc since @Pl45m4 said QSqlField would be a struct.

                                          @JonB said in C++ : call to temporary is a no-op:

                                          @MasterQ said in C++ : call to temporary is a no-op:

                                          full citation:

                                          You wrote/added this after I wrote about using QSqlRecord::setValue(). I am unclear: are you aware that what you show in your "full citation" is not the (best) way to read or write a value in a QSqlRecord (and you should change)? Just checking.

                                          I am not sure if I got you. You mean the version to address the field by name is better as to address by index, right? Since I have full controll about the structure of the database I also have full control of the sequence of the fields. I agree that by name is a safer way to do it. Maybe I will change in future. At the moment there are other issues with higher priority.

                                          While on the topic you mentioned "isn't everything in Qt a QObject" and you are investigating Qt, have you read Implicit Sharing?

                                          No, I was not aware of that topic. Thanks for pointing to.

                                          Christian EhrlicherC Offline
                                          Christian EhrlicherC Offline
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #21

                                          @MasterQ said in C++ : call to temporary is a no-op:

                                          I never claimed object and QObject are the same thing

                                          A QSqlField object can provide some meta-data about the field, ...

                                          meta-data? sounds like QObject.

                                          But you wrote it...

                                          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

                                          • Login

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