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?
Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.
Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in addition to what is already possible by subclassing QStyle. The concepts, terminology, and syntax of Qt Style Sheets are heavily inspired by HTML Cascading Style Sheets (CSS) but adapted to the world of widgets.
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
QTextEdit * userNameEdit = new QTextEdit(this);
If there is ambiguity, such as QListView and QTreeView, pick the last unabiguous section.
QListView * userListView;
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.
Since Qt is open to third party developers, they made available several documentation regarding the coding style and the API design principles.
These documents are really interesting. Here are a few links :
Wiki : Qt Coding Style
Wiki : Api Design Principles
And this document (PDF) from Jasmin Blanchette, which is worth reading : Little Manual of API Design
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With