{
Q_OBJECT
public:
CBase
() : QObject(0) { someProtectedData
= "something here";
};
QString someConstFunction
() const { return someProtectedData;
};
protected:
};
class CDerived : public CBase
{
Q_OBJECT
public:
QString someConstFunction
() { emit someSignal
(); someProtectedData
= "changed";
return someProtectedData;
};
signals:
void someSignal();
};
class CBase : public QObject
{
Q_OBJECT
public:
CBase() : QObject(0) { someProtectedData = "something here"; };
QString someConstFunction() const { return someProtectedData; };
protected:
QString someProtectedData;
};
class CDerived : public CBase
{
Q_OBJECT
public:
QString someConstFunction() { emit someSignal(); someProtectedData = "changed"; return someProtectedData; };
signals:
void someSignal();
};
To copy to clipboard, switch view to plain text mode
Constness removed in derived class. Isn't that which you are trying to do?
Another way is const_cast on "this".
Code above compiles without errors for me. Am I wrong somewhere?
qtneuling, probably you're trying to do something different.
Bookmarks