Unsolved static const QFont using QFontDatabase?
-
Hello Qt community,
this is a follow-up question regarding an earlier thread I started: https://forum.qt.io/topic/58826/qfontdatabase-causes-segfault-solved
Does this mean I can't load a QFont onto a static const class member? static const class members are always evaluated before
main
is run, and unfortunately it is not possible to declare any QApplication instance before that.Thanks in advance for your help.
-
You may init any static member after font is loaded.
-
@SeeLook I'm sorry what? I'm not sure I understood what you were trying to say. Keep in mind that I'd like the static member to be const.
-
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.