Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QFont intialized before QApplication causes segfault with static Qt #54

Closed
oliverdaniell opened this issue Aug 9, 2017 · 5 comments · Fixed by #57
Closed

QFont intialized before QApplication causes segfault with static Qt #54

oliverdaniell opened this issue Aug 9, 2017 · 5 comments · Fixed by #57
Labels
bug resolved ui Issues related to profiler_gui

Comments

@oliverdaniell
Copy link

Initialization of fonts before QApplication is not valid and causes a segfault when linking statically against Qt. This is caused by the initialization of non-local variables before main. eg.

const auto BG_FONT = ::profiler_gui::EFont("Helvetica", 10, QFont::Bold);

This can be fixed by replacing the above with

auto const & BG_FONT() { static const auto BG_FONT = ::profiler_gui::EFont("Helvetica", 10, QFont::Bold); return BG_FONT; }

@oliverdaniell
Copy link
Author

If you agree with the fix I can create a merge request

@yse
Copy link
Owner

yse commented Aug 9, 2017

@oliverdaniell thanks for report.
Of course, you can create request - it will be good!

@cas4ey
Copy link
Collaborator

cas4ey commented Aug 9, 2017

local static QFont may cause problem on VS2013 because it has no c++11 magic statics support.
Please, move it into EASY_GLOBALS

@oliverdaniell
Copy link
Author

oliverdaniell commented Aug 9, 2017

The issue came up on gcc 5.4 so I don't think it's related to differences in the handling of static between c++98 and c++11 (I assume by c++11 magic statics you mean the thread safe initialization?).

I'm not sure why the code works when linking dynamically against Qt. From the doc

Note that a QGuiApplication instance must exist before a QFont can be used

Anyway EASY_GLOBALS looks like the logical place to put it so I will get that done tomorrow.

@cas4ey
Copy link
Collaborator

cas4ey commented Aug 9, 2017

The issue came up on gcc 5.4 so I don't think it's related to differences in the handling of static between c++98 and c++11 (I assume by c++11 magic statics you mean the thread safe initialization?).

Yes, I mean thread safe initialization. I just wanted to say that hiding static QFont inside a function would add additional problems for VS2013 users (and gcc < 4.3) - there are a lot of them still.

Anyway EASY_GLOBALS looks like the logical place to put it so I will get that done tomorrow.

Nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug resolved ui Issues related to profiler_gui
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants