Solved changing a value in a const funktion
-
I don't see where you change 'limit' member var inside TableCustomise::colorData() so what's the problem?
-
@Mogli123 said in changing a value in a const funktion:
I only changed it in the public slot because I thought that the value limit because of that changes in the whole .cpp file but that seems that it is not the right way
Why is it not the right way?
Do you have to change limit inside colorData()? -
@jsulm said in changing a value in a const funktion:
Why is it not the right way?
Because it does not work...^^
Do you have to change limit inside colorData()?
No, I have only to know the current value from
limit
for theif
condition incolorData()
-
@Mogli123 said in changing a value in a const funktion:
Because it does not work
Then why don't you try to find out why it doesn't work instead of trying to change the value in a const method where you don't even have access to the new value?
To find out why it doesn't work (you did not explain in what way it does not work):
-
Did you make sure the slot receiveLimit() was called?
-
If it was called did you check the values of receiveLimit and limit (before assigning new value to limit)?
-
-
@jsulm
with qDebug() I checked if the newlimit
is received and that works.
Only in the constant methodcolorData
the valuelimit
is unchanged
I hoped that the valuelimit
changes in the whole tableCustomise.cpp file, but that does not work because the methodcolorData
is const, but it have it to made the method const, how I mentioned above. (I'm right?)
I have no idea how I can get the current value fromlimit
to the const method for checking if theif
condition is right or notI have no many experience in C++ programming and I hoped that someone can show me a way to solve my problem.
-
@Mogli123
I still don't see what is causing the problemQString TableCustomise :: colorData (const QModelIndex & index) const
A "const function", denoted with the keyword const after a function declaration, makes it a compiler error for this class function to change a member variable of the class. However, reading of a class variable is okay.
You only read limit, -> make limit a normal member
-
however, reading of a class variable is okay.
but the value in the const function
colorData
fromlimit
is not the right value.
Only in the public slotreceiveLimit
the value fromlimit
is right.You only read limit, -> make limit a normal member
Do you mean to remove
mutable
?
If yes, at the beginning I tryed it without the key word -
@Mogli123 There must be something else in your code. If the slot is called and you assign new value to limit then it should have the new value.
Do you have more than one instance of TableCustomise?
Can you show where you create the instance?
Can you show where you connect the signal to receiveLimit() slot?
Is it possible that you have more than one instance of TableCustomise and connect the slot receiveLimit() from one but use limit in another one?
Do you have any other definitions of limit?
Is this really the code you have:void TableCustomise :: receiveLimit (qint32 receiveLimit) { limit = receiveLimit; qDebug () << "limit Adjust on transfer:" << limit; }
?
-
Thank you very much, that was it
I had a second instance of tableCustomise...@J-Hilk
@Christian-Ehrlicher
@VRonin
@JonB
Also thank you, toosorry for my bad explenation
have a nice day -
@Mogli123 said in changing a value in a const funktion:
I had a second instance of tableCustomise
This is an issue I often see here, so you're not the first one who oversees it and for sure not the last one :-)
Can happen :-)