Skip to content

Commit

Permalink
Merge pull request wang-bin#1175 from ThatOdieGuy/examples-logger-fix
Browse files Browse the repository at this point in the history
Adding mutex lock to Logger
  • Loading branch information
wang-bin authored Dec 29, 2018
2 parents 17f2535 330382c commit 4040bd7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 35,7 @@
#include <QtCore/QStandardPaths>
#endif
#include <QtDebug>
#include <QMutex>

#ifdef Q_OS_WINRT
#include <wrl.h>
Expand Down Expand Up @@ -98,8 99,13 @@ QtMsgHandler qInstallMessageHandler(QtMessageHandler h) {
return qInstallMsgHandler(MsgHandlerWrapper::handler);
}
#endif

QMutex loggerMutex;
void Logger(QtMsgType type, const QMessageLogContext &, const QString& qmsg)
{
// QFile is not thread-safe
QMutexLocker locker(&loggerMutex);

const QByteArray msgArray = qmsg.toUtf8();
const char* msg = msgArray.constData();
switch (type) {
Expand Down

0 comments on commit 4040bd7

Please sign in to comment.