[Qt-interest] Organizing error message strings
André Somers
andre at familiesomers.nl
Wed Apr 7 08:21:04 CEST 2010
Hi,
Interesting question.
IMHO, using a QMap (or better yet, a QHash) would be a reasonable approach.
I think youll just have to try if the initialization time of a suitably
large QMap or QHash would take too much time for you. My guess would be that
it is not an issue. You can speed up initialization a bit by calling
QHash::reserve. Why dont you create a small test to see how much time it
actually takes to initialize a QHash like that with 10,000 messages or so? A
simple loop would give you a rough estimate.
André
Van: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Namens John Weeks
Verzonden: dinsdag 6 april 2010 18:34
Aan: qt-interest at trolltech.com
Onderwerp: [Qt-interest] Organizing error message strings
Hi, all!
I'm in the process of porting a very large application to Qt. There are
thousands of error messages, and I'm trying to figure out the Qt way to
organize such a large number of strings.
We need:
1) to be able to localize the messages, so it will involve using tr(),
clearly.
2) to retrieve the messages based on an error code. Something like:
QString msg = GetErrorMessage(errorcode)
3) to make it *easy* for developers to add new messages. If it's not easy,
then they won't do it, and we get messages like "Syntax error" because they
just use something that's already there.
I've thought about using something like
QMap<int, QString> messageMap
messageMap.insert(oneErrorCode, tr("You made a mistake"))
It would make look-up easy and fast, but it seems like this approach
requires a lot of initialization at start-up. The problem, obviously, is
entering and storing the strings in a way that makes for easy look-up.
What have others done to solve this problem? Is there a "Qt Way" to do this?
Thanks!
Regards, John Weeks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100407/6cf3c17a/attachment.html
More information about the Qt-interest-old
mailing list