Reputation: 79685
In one of my classes I have a member "QSize frameSize". I wanted to make a getter function for it, and naturally I thought about "QSize frameSize()" but that would be the same as the variable name! In Qt the convention is not to use getFrameSize, so how do they avoid name collisions in their own source code?
Upvotes: 1
Views: 3167
Reputation: 4412
If you are trying to extend Qt with your own classes, it's generally foo()
and setFoo()
, internally you could use m_foo
or simply _foo
. Take a look at the source if you want to be precise.
There are many ways of naming things and ultimately it comes down to preference (yours or your employer's). It's not too important so long as you're consistent and clear. This advice extends to Qt's dynamic properties too.
Upvotes: 0
Reputation: 94539
Well - first of all: use the source, Luke! The Qt source code is available under open-source licenses, so you're free to check how they're doing things.
That being said, in the vast majority of cases Qt doesn't have this problem because most public classes only have a single member variable (a "d-pointer") since they implement the pimpl idiom. So they might have functions like
int QSomeThing::foo() const {
return d->foo;
}
Last but not least, I'm not aware of any global naming rule for member variables in the Qt source code, but there are a few well-established conventions. The one I happen to use is to prefix the name of all member variables with m_
(denoting that it's a member). So the above function, in my source code, would (assuming I don't use the pimpl idiom) look like:
int QSomeThing::foo() const {
return m_foo;
}
Your mileage may vary.
Upvotes: 9