Qt小部件的命名约定 [英] Naming convention for Qt widgets

查看:120
本文介绍了Qt小部件的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一组其他程序员在一个使用C ++和Qt构建的开源项目上工作。



现在,我们需要一个命名约定其他变量一般)使用它作为所有代码的标准,这样,代码获得更好的可读性,我们得到更好的协调程序员之间。



任何建议? / p>

编辑:我不是在谈论命名新类,



而是我说的命名实例Qt Widgets,让我们说我有一个文本编辑用户名,我应该命名为txtEdtUsrNm?



在这种情况下,我应该如何选择派生?

解决方案

只要你沿着这些思路,我就会从头到尾阅读这篇QtQuarterly文章。



设计Qt风格的C ++ API



也就是说,我们做的一件事是将实例的use作为类的第一部分和最后一个完整字



因此,您的用户名QTextEdit是

  QTextEdit * userNameEdit = new QTextEdit(this); 

如果存在歧义,例如QListView和QTreeView,请选择最后一个不明确的部分。

  QListView * userListView; 

你可以找出你喜欢的缩写(例如QLabel的Lbl),整个单词已经工作并且很容易阅读。



另一方面,我们并不太严格这一点,它可能更重要的是命名的意图实例变量没有类名,因为如果,在将来,你想改变类,你得到改变的名称,如果没有好的重构工具,是一个痛苦。



也许找出你使用最多的一般小部件,并为最常见的超类选择一个命名约定,并让一切超越。



符合约定的事物示例列表:




  • layout =所有以
    Layout结尾的类并继承QLayout

  • button =以Button结尾并继承QAbstractButton的所有类



QAbstract ClassName 类是考虑该列表中应该包含的内容的好地方。


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

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:

  • layout = All classes that end in "Layout" and inherit QLayout
  • button = All classes that end in "Button" and inherit QAbstractButton

The QAbstractClassName classes are a good place to think about what should be in that list.

这篇关于Qt小部件的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆