[Qt-creator] Keeping UI strings consistent
Kyle Evans
kyledevans at gmail.com
Tue Feb 28 20:53:09 CET 2012
So I've been working on a project that helps track prescriptions and
inventory. Some data (IE: the name of a medication) is displayed in
several locations throughout the app. The problem arises when I need
to make a tooltip or a QLabel that describes what information is being
displayed. If I change a tooltip or QLabel in one .ui file, then I
have to manually go and change every QLabel and tooltip so that the
app has consistent strings.
For example I have some widgets that appear like so:
"Medication name: <medication_name_is_inserted_here>"
In another place in the application I have some QTableWidgets that
display results from a SQL query. The column headings would appear
like so:
"...... | Medication name | ......"
My interest is keeping the strings "Medication name" identical if for
example I changed one to simply "Medication". I currently have the
following solutions in mind for achieving this:
1) When using the UI designer, simply put placeholder strings which
are then replaced by global strings in C++.
- Allows changing a string in one location and have it take effect
everywhere in the app.
- Adds a ton of C++ code. A single widget with 10 strings can
easily add up to 40 lines of code.
- Partially removes the advantages of using the UI designer.
2) Using QtTrId().
- Requires that I do solution 1 with slight modifications to use the
translation system.
- Doesn't work with strings defined in the ui designer.
3) Just keep track and stop being a baby. Keep a list of every
location that a string appears. When one is changed, I look up where
else I need to update and manually keep everything consistent.
- Doesn't clutter up C++ files with hundreds of string assignments.
- Makes changing UI strings a real pain.
- No easy way to verify that I didn't forget to update a string someplace.
I'm currently using solution 1, since I wanted to get the application
ready and don't know anything about Qt translation infrastructure. It
adds a lot of simple string assignment code in my classes while making
the UI designer contain a bunch of placeholder text.
--
-- Kyle Evans
More information about the Qt-creator
mailing list