passing 'const QSqlQuery' as 'this' argument discards qualifiers
-
Hi All,
I'm trying to migrate from Qt5.6 to Qt6.5 my project is heavily SQL based...
At my Class at header... I define a
QSqlQueryModel *modKomponent;
At my class constructor
modKomponent = new QSqlQueryModel;
on the form one of the button
modKomponent->query().next()
then I get error for "modKomponent->query().next()"
passing 'const QSqlQuery' as 'this' argument discards qualifiers
How can I solve it?
thanks
-
Hi All,
I'm trying to migrate from Qt5.6 to Qt6.5 my project is heavily SQL based...
At my Class at header... I define a
QSqlQueryModel *modKomponent;
At my class constructor
modKomponent = new QSqlQueryModel;
on the form one of the button
modKomponent->query().next()
then I get error for "modKomponent->query().next()"
passing 'const QSqlQuery' as 'this' argument discards qualifiers
How can I solve it?
thanks
@zeroptr
const QSqlQuery &QSqlQueryModel::query() constThe
const
at the beginning means that theQSqlQuery
it returns is const/read-only. You cannot/are not supposed to do anything to it which alters it. ButQSqlQuery::next()
does (or may) alter it, e.g. changing its internal state. Hence the error message.You are clearly not intended to do anything to modify the query returned by
QSqlQueryModel::query()
(I imagine it manages it all internally). I don't know why you got away with this at Qt5, whether you were never supposed to or it is an actual change in behaviour at Qt6. I guess you should review why you are trying to callnext()
on it when you should be letting theQSqlQueryModel
handle its query without interference. -
@zeroptr
const QSqlQuery &QSqlQueryModel::query() constThe
const
at the beginning means that theQSqlQuery
it returns is const/read-only. You cannot/are not supposed to do anything to it which alters it. ButQSqlQuery::next()
does (or may) alter it, e.g. changing its internal state. Hence the error message.You are clearly not intended to do anything to modify the query returned by
QSqlQueryModel::query()
(I imagine it manages it all internally). I don't know why you got away with this at Qt5, whether you were never supposed to or it is an actual change in behaviour at Qt6. I guess you should review why you are trying to callnext()
on it when you should be letting theQSqlQueryModel
handle its query without interference.@JonB with Qt5 you get the same compiler error. QSqlQuery::next() was never const.
-
Hi All,
I'm trying to migrate from Qt5.6 to Qt6.5 my project is heavily SQL based...
At my Class at header... I define a
QSqlQueryModel *modKomponent;
At my class constructor
modKomponent = new QSqlQueryModel;
on the form one of the button
modKomponent->query().next()
then I get error for "modKomponent->query().next()"
passing 'const QSqlQuery' as 'this' argument discards qualifiers
How can I solve it?
thanks
@zeroptr
Then per @Christian-Ehrlicher's comment it should never have worked at Qt5 either....The
QSqlQuery
assigned to aQSqlTableModel
is for its use internally, to fetch all the rows from a table. You should never either need or want to callnext()
on it to fetch any further rows. If you want to do your ownnext()
ing to fill a result set, for some reason, use your ownQSqlQuery
to do so, not one in use by a table or query model. -
@zeroptr
Then per @Christian-Ehrlicher's comment it should never have worked at Qt5 either....The
QSqlQuery
assigned to aQSqlTableModel
is for its use internally, to fetch all the rows from a table. You should never either need or want to callnext()
on it to fetch any further rows. If you want to do your ownnext()
ing to fill a result set, for some reason, use your ownQSqlQuery
to do so, not one in use by a table or query model.@JonB after reconsideration it might have worked when the const ref was copied to a new QSqlQuery instance
This copy was removed in Qt6 as it's impossible to copy a query without getting strange side effects in the underlying layer.