How do I access private variable of an object ?
-
I have limited access to the object , but I can retrieve data of interest - in this case dimensions of one of the GUI objects.
Form_Widget *FW = new Form_Widget(); // object
QRect dimensions = FW->geometry(); // returns dimensions of specific part of the object
int start_X = dimensions.x2; //can't do, QRect / dimensions are private -
I have limited access to the object , but I can retrieve data of interest - in this case dimensions of one of the GUI objects.
Form_Widget *FW = new Form_Widget(); // object
QRect dimensions = FW->geometry(); // returns dimensions of specific part of the object
int start_X = dimensions.x2; //can't do, QRect / dimensions are privateOne of the steps I invariably do, when debugging, is comment-out private blocks ... essentially rendering all statements public. Now that I get typing ... and that's just for starters. Without the essential error code (warning?) accompanying a successful compilation/link/running blank form ... there's little more time expendable for me, especially if you're already running debugger and just don't care to get descriptive enough with words and include a code. So, I'll just cut to the chase.
-
I have limited access to the object , but I can retrieve data of interest - in this case dimensions of one of the GUI objects.
Form_Widget *FW = new Form_Widget(); // object
QRect dimensions = FW->geometry(); // returns dimensions of specific part of the object
int start_X = dimensions.x2; //can't do, QRect / dimensions are private -
Sorry, I posted this is wrong forum. But to the comedians - do not quit you day job. In the mean time I'll looking at usage of "friend".
Member 14968771 wrote:
In the mean time I'll looking at usage of "friend".
Don't waste your time, since it will not make any difference. You cannot declare your class to be a friend of some other class in the hope of accessing its private variables. If that was possible then the millions of applications would be open to hacking. Do what I suggested above and make use of the information provided in the documentation: that is what it is there for..
-
Member 14968771 wrote:
I guess height and width are QRect public variables derived from "private" data.
No, they are public methods that give you read-only access to private members.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Sorry, I posted this is wrong forum. But to the comedians - do not quit you day job. In the mean time I'll looking at usage of "friend".
It was serious, actually. If you the designer of the class made a member
private
then you have two ways to access it: the publicly exposed interface (for instance theget/set
methods) or a dirty hack on its bare representation in memory. Typically you cannot usefriend
because you are not the designer of the class."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
I have limited access to the object , but I can retrieve data of interest - in this case dimensions of one of the GUI objects.
Form_Widget *FW = new Form_Widget(); // object
QRect dimensions = FW->geometry(); // returns dimensions of specific part of the object
int start_X = dimensions.x2; //can't do, QRect / dimensions are privatePrivate members are only accessible via public functions. Try int start_X = QPoint.SetX(dimentions.x2);