Re: Problem with the const
form::calculate() is expecting a pointer to a QString and CustomSql::data is sending it a pointer to char. Is that what you intended?
Note: Original poster has changed the code above since this post was written.
Re: Problem with the const
actually normaly I try to sent
Code:
index.sibling(index.row(),3).data().toString()
but I get the error
... as this argument of 'double ....' discard qualifiers...
Re: Problem with the const
Code:
"11"; // <- this is const char *
so you cannot pas it to method which wants a QString *. Do you really need a QString * type? Are you really changing the given string and those changes should have been visible to the caller? Then passing something like "11" really doesn't make any sense. I would say that this is an error of your class methods architecture as your method is prepared for different use then you will need. What do you want to achieve by passing pointer?
Re: Problem with the const
just change the code, please check the message again.
What I am doing is for a qtableview I am getting a value from 3rd row, and I send to a function in another class to calculate it. I need to send a string to calculate the value of it. In return I need this double to be on column 5th.
Re: Problem with the const
Did he change the code snippets? Where do you see QString pointers? Or something '11'? It is very annoying to do so and does not make it easier to help. But your problem is that you try to call a non-const method from a const method. Of course this does not work.
Re: Problem with the const
yes I know that is mistake but I need to solve it somehow
I cant change the function calculate
Re: Problem with the const
What you do is ugly, really ugly introducing a side-effect into data method of your model. But if you really want to do that... your funeral.
What you can do is remove the constness of the this pointer in your data method using const_cast. cost_cast<CustomSql *>(this)->calculate....
Good Luck
Re: Problem with the const
Quote:
Originally Posted by
aekilic
What I am doing is for a qtableview I am getting a value from 3rd row, and I send to a function in another class to calculate it. I need to send a string to calculate the value of it. In return I need this double to be on column 5th.
Code:
if (index.column() == 5){
calculate(index.sibling(index.row(),3).data().toString());
}
You are discarding the return value from the function: the result won't appear anywhere.
Re: Problem with the const
this is why I forget to write
normaly code is like this
Code:
if (index.column() == 5){
double d = form.calculate(index.sibling(index.row(),3).data().toString());
return QString("%L1").
arg((d
),
0,
'f',
2).
leftJustified(true);
}
Re: Problem with the const
So can you paste your exact code? Because none of your snippets makes any sense. Maybe the last one is a bit more clear but still we can't deduce how form was declared and what the hell it is? :P In previous snippets you had calculate in different classes and calling it as it would be in one class... And what is:
??
And can you paste the exact error you get?
Re: Problem with the const
form.h
Code:
class form
:public QDialog, Ui
::form{
Q_OBJECT
public:
bool isUpdate;
public slots:
double calculate
(const QString &id
);
};
#endif
form.cpp
Code:
double form
::calculate(const QString &id
) {
totaID = id;
load();
return spin->value();
}
and after that I create a custom sqltablemodel
Code:
{
if (value.isValid() && role == Qt::DisplayRole) {
if (index.column() == 5){
calculate(index.sibling(index.row(),3).data().toString());
return QString("%L1").
arg((d
),
0,
'f',
2).
leftJustified(true);
}
return value.toString().leftJustified(true);
}
return value;
}
am I clear?
Re: Problem with the const
No, your code doesn't make any sense. You didn't show us your CustomSql::calculate() method, and d is undefined. Also load() method is not defined. And we still don't know what is the exact error you get?
Re: Problem with the const
I have a quick question for you...
Why would you want to recalculate the value over and over again when something calls data()?
In other words - why not calculate it once when it changes and then just return the earlier calculated value from data()?