Fixed race condition with model not being assigned.

This commit is contained in:
0xFEEDC0DE64
2017-12-28 23:15:35 +01:00
parent 0a96e22c66
commit d624ca9719

View File

@@ -21,13 +21,12 @@ void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const Q
{ {
previousHandler(type, context, message); previousHandler(type, context, message);
if(!model)
model = std::make_shared<LogModel>();
model->log(type, context.file, context.line, context.function, context.category, message); model->log(type, context.file, context.line, context.function, context.category, message);
} }
void registerMessageHandler() void registerMessageHandler()
{ {
model = std::make_shared<LogModel>();
previousHandler = qInstallMessageHandler(myMessageHandler); previousHandler = qInstallMessageHandler(myMessageHandler);
} }
@@ -58,5 +57,5 @@ void DevToolsPlugin::attachTo(MainWindow &mainWindow)
auto dialog = new LogDialog(&mainWindow); auto dialog = new LogDialog(&mainWindow);
dialog->setModel(model.get()); dialog->setModel(model.get());
mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/devtoolsplugin/images/dev-tools.png")), mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/devtoolsplugin/images/dev-tools.png")),
tr("Show log"), dialog, &QDialog::open); tr("Show log"), dialog, &QWidget::show);
} }