C++ : call to temporary is a no-op
-
@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
andQObject
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 aQSqlRecord
(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.
@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...
-
M MasterQ has marked this topic as solved on
-
@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
andQObject
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 aQSqlRecord
(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.
@MasterQ said in C++ : call to temporary is a no-op:
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?
No. I am saying your way of coding, going via a
QSqlField
and commenting on the copying/temporaries etc. is "wrong", at least efficiency-/lines-of-code-wise, for both writing and reading your fields. (Nothing to do with integer indexing vs name indexing, they are just alternatives, integer indexing is faster.) You do not and should not need to accessfield()
at all in either. You simply need:int id() const { return value(Id).toInt(); } void setId(int id) { setValue(Id, id); }
and so on for all your field getters/setters. None of that 3-lines-to-set! Do not go via QSqlRecord::field() at all, forget about
QSqlField
, just use QSqlRecord::value()/setValue().