Unsolved How to name Qlabel?
-
Hello,
This is not question stricte about QT, but I use QT, so... :)
Very often I have situation when I have 2 QWidgets: QLabel and QLineEdit.
QLabel has fixed text for example "Age:" and QLineEdit is the widget with empty place, where I can write age ( for example "32" ). How I should name that QWidgets? I know that there are different schools, but how will you name this widgets?
I write:
QLabel ageTextInfo;
QLineEdit ageLineEdit;But I think there can be better way.
-
@TomNow99
I don't! It's not very Qt, and I'll probably be shouted at, but I cannot cope with spelling out a full widget-type at the end of the variable name, it just doesn't scan for me looking through code. I pick an abbreviation for each widget type and stick with that throughout. So without hesitation I would name these variableslblAge
andleAge
(ortxtAge
oreditAge
if you prefer), and I'm very happy with that :) (For whatever reason, I only adopt this pattern for GUI-widget variables.) -
@TomNow99 since there's no guarantee, that the actual widget types stay during the whole of the development (for example you could change from a lineEdit to a textedit or to a custom widget) and I don't want misleading names or want to have to rename everything, I would go with
ageInfo
ageEdit -
@J-Hilk said in How to name Qlabel?:
since there's no guarantee, that the actual widget types stay during the whole of the development (for example you could change from a lineEdit to a textedit or to a custom widget) and I don't want misleading names or want to have to rename everything
That's what Creator Rename Symbol Under Cursor is for ;-) But of course each to their own.
-
@JonB well, yes, but will the new name fit neatly into all your indentions ? 😅
Also I don't like to rely on thus macros, if I can avoid it! -
@J-Hilk
Rename Symbol Under Cursor is not a macro :)
It uses clang AST to do exact replacements on the actual variable.
so no whops as with text-based search and replace :) -
@mrjj said in How to name Qlabel?:
@J-Hilk
Rename Symbol Under Cursor is not a macro :)
It uses clang AST to do exact replacements on the actual variable.
so no whops as with text-based search and replace :)Fair enough,
and since there is absolutely no problem with clang in QtCreator (🙈), I will have not to worry about something going wrong 😉
-
@J-Hilk
hehe i know what you mean...
but oddly enough the replace function is very reliable compared to clang code model in general.
7-9-13 is has not yet fuxed up something that was not my own fault.
It shows a checkable hit list and one has superfine control of what gets replaced.
But its more safe if one has a naming that wont need refactoring if widget type changes. :)