Will preparing and executing QSqlQuery change the boolean constant of the method that does it?

I have a QScopedPointer for QSqlQuery which is a member variable of a class.

I want to initialize, prepare and execute QSqlQuery in a method that is a constant. The consciousness of the method will not allow me to do this. There are 2 options. Remove the constant from the method, or add the mutable keyword to the member variable. Which is better and why?

I read that I should only use mutable when modifying the variable does not affect the "boolean constant" of the method / object. What is a boolean constant and will it change in my case?

+3


source to share


1 answer


It depends on the rest of your class. When you prepare a query in QSqlQuery, you change the state of one of the data members. So the method is not purely "const".



What should make your decision is how the rest of your class members interact with the QSqlQuery member. If the state of the query is irrelevant to the state of your object, that is, none of your other methods will care if the prepared query in the QSqlQuery data item has changed, making mutable a great option. If modifying the prepared statement has consequences elsewhere, then the method must not be const.

0


source







All Articles