Unsolved static const QFont using QFontDatabase?
-
Hi,
Why do you need a static QFont ?
-
Hi @SGaist,
Basically I need a global variable, and I don't intend to change it once I declared it.
-
That's what I thought but what would be the use of that global QFont ?
-
@SGaist It would be used whenever a few functions are run. I'm just trying to load it once and for all, rather than load it every time these functions are called. The use is drawing texts on a QImage.
-
Are these functions in separated classes ?
-
No they are all in that same class.
-
Then why not just make it a member and load it at construction time ?
-
@SGaist I could do that, but it's the same font for all instances. So it would be kind of a waste of space.
-
Simply add static init() method to the class where private static QFont is done and give access to it through const method
QFont myFont () const { return m_font; }
-
So it would be kind of a waste of space.
Hello,
I suggest answering these two questions for your own peace of mind:- How much space would you expect to save if you put it in a static variable?
- What do you gain or lose by making it a static and is it worth the effort (in work time/planning time)?
Kind regards.