[Interest] Can QObject::tr() be used in initialization of static const QString data members? [Qt 5.5.1, Windows]
Matthew Woehlke
mwoehlke.floss at gmail.com
Tue Nov 10 20:18:30 CET 2015
On 2015-11-10 13:00, Thiago Macieira wrote:
> On Tuesday 10 November 2015 11:31:57 Matthew Woehlke wrote:
>> On 2015-11-09 17:35, Thiago Macieira wrote:
>>> I advise against static QStrings altogether. Just don't do that.
>>
>> What's the problem with static QString?
>
> There's no actual error or problem, but it's just poor coding practice.
>
> It's a static non-trivial type. We avoid those in Qt, so I make the
> recommendation to everyone, everywhere.
>
> Static non-trivials imply a load-time and exit-time overhead, even if you
> never use that variable again. Better to initialise on first use and make sure
> you really need to cache the result.
Okay, that makes sense. Thanks for the clarification. (Most of my use is
function-local statics, so IIUC no load-time penalty, i.e. your "better
to..." above. Mostly my theory there is: the memory is cheap, why
construct a constant string more than once?)
--
Matthew
More information about the Interest
mailing list