Skip to content

Commit

Permalink
QGuiApplication: drop mutex before emitting fontChanged()
Browse files Browse the repository at this point in the history
Emitting a signal executes an unknowable amount of code. We shouldn't
hold a mutex while doing so. E.g., if the signal emission causes
another call to QGuiApplication::setFont(), the old code would
deadlock, since applicationFontMutex is not recursive.

Fix by taking a copy of the application font under mutex protection,
then dropping the lock for the emission of the signal.

Change-Id: Ib2569b3a08af6ef5f38459a19f74cb0db27b7772
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Lars Knoll <[email protected]>
  • Loading branch information
marc-kdab committed Aug 23, 2019
1 parent b1db1dd commit 96ff6e8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/gui/kernel/qguiapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3284,8 +3284,11 @@ void QGuiApplication::setFont(const QFont &font)
*QGuiApplicationPrivate::app_font = font;
applicationResourceFlags |= ApplicationFontExplicitlySet;

if (emitChange && qGuiApp)
emit qGuiApp->fontChanged(*QGuiApplicationPrivate::app_font);
if (emitChange && qGuiApp) {
auto font = *QGuiApplicationPrivate::app_font;
locker.unlock();
emit qGuiApp->fontChanged(font);
}
}

/*!
Expand Down

0 comments on commit 96ff6e8

Please sign in to comment.