sss93 0 Newbie Poster

I have a class orders which has its instanced stored in a QMap/Map and has a Key:int, value:order pattern. Everything went fine until I started iterating through the map and accessing the functions of the class.First I was trying to print out the order objects values using it's getter methods for example:
orderSet.value(i).getDate().toString("dd/MM/yyyy"); //OrderSet is my map

This however produced an error
error: passing 'const order' as 'this' argument of 'QDate order::getDate()' discards qualifiers [-fpermissive]
I then fixed this by adding 'const' to the getter methods and the previous line of code would successfully run and print out that objects date as a string.

However now the issue is I cant implement my setter methods because I would get the same error, and obviously the setter method has a line which alters the original member variable so this in itself would violate the constant rule, so how can I alter the object variables which is stored inside a Map a map ??

heres my code if it helps:

class order
{
    QDate dateOrdered;
    int totOrders;
    double totValue;

public:
   order();
   order(QDate,int,double);
   //Sets
   void setDate(QDate); //Cant add const since values are being altered
   void setOrderTot(int);
   void setValueTot(double);

   //Gets
   QDate getDate() const; //Adding const solved these methods 
   int getOrderTot()const;
   double getValueTot()const;

};

#endif // ORDER_H

example of use:

function buttonOkPress(....){
     order myOrder(date,4,32);
     Mymap[index]=myOrder;
}

function printBack(...){
    qDebug/cout <<    myMap->value[i].getDate().toString(""dd/MM/yyyy); // For this to work needed to change method type to constant
    myMap->value[i].setDate()...; Calling this wont work ???

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.