我的类的名称应该在Qt中以“Q”开头吗? [英] Should the name of my classes begin with 'Q' in Qt?

查看:312
本文介绍了我的类的名称应该在Qt中以“Q”开头吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我第一次使用Qt,这是非常讨厌的,每个类有一个名称以'Q'开头,但现在我习惯了。



我使用Qt Creator,它突出代码很好。

然而,它只突出显示类名以'Q'开头。它突出显示以Q开头的所有内容,即使没有这样的类型。

它不强调自定义类名。



我想知道,我应该用'Q'开始我的所有类名吗?

或至少是可重用的?

(我的意思是,那些我放在类库中,或在其他应用程式中重复使用。)



我见过几个地方,他们这样命名他们的类。这是好事吗?



我发现此页关于Qt的命名约定,但它不处理这个问题。



另外,我不明白为什么Qt不使用命名空间。 p>

编辑



感谢大家与我分享他的想法。 / p>

编辑2:



似乎较新版本的Qt Creator突出显示不以Q开头的类名。很好!

解决方案

人为地,我不会为自己的类添加前缀。由于Qt有自己的实现很多东西(字符串,列表...)它有助于知道你使用什么。



正确的方法是使用命名空间。我认为Qt没有使用它们,因为它很老了。 C ++最近改变了很多。



一般来说,根据语法着色修改命名约定是一个坏主意(即使我知道它只是让你想知道你的命名)。


When I first started working with Qt, it was extremely annoying that every class has a name beginning with 'Q', but now I've got used to it.

I'm using Qt Creator, and it highlights code quite well.
However, it only highlights class names beginning with 'Q'. And it highlights everything beginning with 'Q' even if there is no such type.
It doesn't highlight custom class names.

That makes me wonder, should I also begin all my class names with 'Q'?
Or at least the reusable ones?
(I mean, those that I put in a class library, or reuse in another app.)

I've seen several places where they named their classes this way. Is it a good thing?

I found this page about Qt's naming conventions, but it doesn't deal with this question.

Also, I don't understand why Qt doesn't use namespaces.

EDIT:

Big thank you to everyone who shared his thoughts with me.

EDIT 2:

It seems that the newer versions of Qt Creator now also highlight the class names not beginning with 'Q'. Nice!

解决方案

Personnally, I wouldn't prefix my own classes. As Qt has its own implementation of lots of thing (string, list...) it helps to know what you're using.

The correct way would be to use namespaces. I think that Qt didn't use them because it's quite old. C++ changed a lot lately.

And generally, adapting your naming conventions according to syntax colouring is a bad idea (even if I understand that it only made you wonder about your nameming).

这篇关于我的类的名称应该在Qt中以“Q”开头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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