I’m working with a group of other programmers on an open source project built using C++ and Qt.
Now, we need a naming convention for widgets (and other variables generally) to use it as a standard in all of our code so that, the code gets better readability and we get better coordination between programmers.
Any advice?
EDIT: Am not talking about naming new classes,
instead I am talking about naming instances of Qt Widgets, let’s say I have a text edit for user name, should I name it txtEdtUsrNm?
And in that case, how am I supposed to choose derivations?
As long as you are thinking along these lines, I’d start by reading this QtQuarterly article from start-to-finish.
Designing Qt-Style C++ APIs
That said, one thing that we do is to put the ‘use’ of the instance as the first part and the last full word of the class as the last part.
So, your ‘user name’ QTextEdit is
If there is ambiguity, such as QListView and QTreeView, pick the last unabiguous section.
You can figure out abbreviations how you like (such as ‘Lbl’ for QLabel), but generally, the whole word has worked and has been easy to read.
On the other hand, we are not too strict about this and it might be more important to name the intention of the instance variable without the class name because if, in the future, you want to change the class, you get to change the name which, in the absence of good refactoring tools, is a pain.
Maybe figure out the general widgets you use the most, and pick a naming convention for the most general super-classes and let everything else go.
Example list of things that adhere to the convention:
The QAbstractClassName classes are a good place to think about what should be in that list.