[Kde-finance-apps] Problem Using getter and Setter Function
Mukesh Gupta
mukesh.gupta2011 at ece.dce.edu
Wed Jun 23 16:13:17 CEST 2010
Hello Cristian,Thomas,
Thanks for reply.What i was trying to do is access/set all member varibales
using getter/setter functions.
I knew how to define the functions but did not know how to access them. I
was confused whether to use them as normal functions or these could be used
as variable after setting the property as thomas pointed out. Well, this is
clear now.
Thanks,
Regards,
Mukesh
On Wed, Jun 23, 2010 at 7:24 PM, Cristian Oneţ <onet.cristian at gmail.com>wrote:
> 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
> _______________________________________________
> Kde-finance-apps mailing list
> Kde-finance-apps at kde.org
> https://mail.kde.org/mailman/listinfo/kde-finance-apps
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/kde-finance-apps/attachments/20100623/799bceaa/attachment-0001.htm
More information about the Kde-finance-apps
mailing list