Hello Cristian,Thomas,<br><br>Thanks for reply.What i was trying to do is access/set all member varibales using getter/setter functions. <br>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.<br>
Thanks,<br>Regards,<br>Mukesh<br><br><div class="gmail_quote">On Wed, Jun 23, 2010 at 7:24 PM, Cristian Onež <span dir="ltr"><<a href="mailto:onet.cristian@gmail.com">onet.cristian@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">On Wed, Jun 23, 2010 at 4:41 PM, Mukesh Gupta<br>
<<a href="mailto:mukesh.gupta2011@ece.dce.edu">mukesh.gupta2011@ece.dce.edu</a>> wrote:<br>
> Hello Friends,<br>
> I am trying to use getter and setter functions in my class but facing a<br>
> problem. My code goes as follows;<br>
><br>
> AlkRecord.h<br>
><br>
> ...<br>
> ....<br>
> Class Alkrecord<br>
> {<br>
> ....<br>
> public:<br>
><br>
> Q_PROPERTY(QString source READ source WRITE setsource);<br>
> //setter function<br>
> void setsource (const QString& source)<br>
> {<br>
> m_source=source;<br>
> }<br>
><br>
> //getter function<br>
> QString source() const<br>
> {<br>
> return m_source;<br>
> }<br>
><br>
> private:<br>
> .....<br>
> QString m_source;<br>
> .....<br>
> };<br>
><br>
><br>
><br>
> AlkRecord.cpp<br>
><br>
> .......<br>
> ......<br>
> AlkRecord::AlkRecord(QString const& Src, QString const& Memo, QString const&<br>
> Amount)<br>
> {<br>
> ........<br>
> source= Src;<br>
> .......<br>
> }<br>
><br>
><br>
> The error is as follows:<br>
><br>
> error: invalid use of member (did you forget the ‘&’ ?)<br>
> This error is in the line shown in bold<br>
><br>
> Shouldn't the setter function be called when i try to assing source with<br>
> some value.<br>
> Also how do i get the value of m_variable using getter function.<br>
<br>
</div></div>Hi,<br>
<br>
I think I know what you are trying to do here but I don't quite get it<br>
why did you thought to write it that way. If you want m_source to get<br>
the value Src you should just write:<br>
<br>
m_source = Src;<br>
<br>
or using the setter<br>
<br>
setSource(Src);<br>
<br>
'source' get's you the address of the member function and you are<br>
trying to assign a string to it.<br>
<br>
BTW: variables usually start with lover case in the convention we use.<br>
<br>
Regards,<br>
Cristian<br>
_______________________________________________<br>
Kde-finance-apps mailing list<br>
<a href="mailto:Kde-finance-apps@kde.org">Kde-finance-apps@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kde-finance-apps" target="_blank">https://mail.kde.org/mailman/listinfo/kde-finance-apps</a><br>
</blockquote></div><br>