[Kde-finance-apps] Problem Using getter and Setter Function
Cristian Oneţ
onet.cristian at gmail.com
Wed Jun 23 15:54:08 CEST 2010
On Wed, Jun 23, 2010 at 4:41 PM, Mukesh Gupta
<mukesh.gupta2011 at ece.dce.edu> wrote:
> Hello Friends,
> I am trying to use getter and setter functions in my class but facing a
> problem. My code goes as follows;
>
> AlkRecord.h
>
> ...
> ....
> Class Alkrecord
> {
> ....
> public:
>
> Q_PROPERTY(QString source READ source WRITE setsource);
> //setter function
> void setsource (const QString& source)
> {
> m_source=source;
> }
>
> //getter function
> QString source() const
> {
> return m_source;
> }
>
> private:
> .....
> QString m_source;
> .....
> };
>
>
>
> AlkRecord.cpp
>
> .......
> ......
> AlkRecord::AlkRecord(QString const& Src, QString const& Memo, QString const&
> Amount)
> {
> ........
> source= Src;
> .......
> }
>
>
> The error is as follows:
>
> error: invalid use of member (did you forget the ‘&’ ?)
> This error is in the line shown in bold
>
> Shouldn't the setter function be called when i try to assing source with
> some value.
> Also how do i get the value of m_variable using getter function.
Hi,
I think I know what you are trying to do here but I don't quite get it
why did you thought to write it that way. If you want m_source to get
the value Src you should just write:
m_source = Src;
or using the setter
setSource(Src);
'source' get's you the address of the member function and you are
trying to assign a string to it.
BTW: variables usually start with lover case in the convention we use.
Regards,
Cristian
More information about the Kde-finance-apps
mailing list