Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should the name of my classes begin with 'Q' in Qt?

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!

like image 594
Venemo Avatar asked May 27 '10 14:05

Venemo


3 Answers

I can't see why you would want to enforce this on your own classes at all. Let Qt do what it wants to do with its class naming convention and you do your own.

like image 161
Troubadour Avatar answered Nov 01 '22 00:11

Troubadour


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).

like image 41
Tristram Gräbener Avatar answered Nov 01 '22 00:11

Tristram Gräbener


Use your own coding convention and standards, it doesn't have to match the library you're using. I don't think the makers of Qt are implying that you follow their style conventions.

like image 8
Brian R. Bondy Avatar answered Nov 01 '22 01:11

Brian R. Bondy