[Qt-interest] Organizing error message strings
John Weeks
john at wavemetrics.com
Wed Apr 7 21:48:29 CEST 2010
Thank you, André.
On Apr 6, 2010, at 11:21 PM, André Somers wrote:
> Interesting question.
> IMHO, using a QMap (or better yet, a QHash) would be a reasonable
> approach. I think you’ll 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 don’t 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.
Hm. Good point. So I wrote a class to wrap the error messages that
uses a QMap<int, QString>. The constructor looks like this:
ErrorStrings::ErrorStrings()
{
messageMap.insert(1, tr("out of memory"));
messageMap.insert(2, tr("expected wave name"));
messageMap.insert(3, tr("syntax error"));
messageMap.insert(4, tr("expected comma"));
messageMap.insert(5, tr("expected name of active axis"));
etc.
There are almost 1319 strings. Using QTime to get the time required to
run the constructor returns 1 mS, which is the resolution of
QTime::elapsed(). So I guess my fears on that score were groundless!
QMap has no reserve() function. I suppose that's because it's based on
a list structure rather than an array.
I'm still wondering if this is the Qt Way. Or maybe my application is
unusual?
Regards,
John Weeks
WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
email support at WaveMetrics.com
More information about the Qt-interest-old
mailing list