Qt: Crash fix

This commit is contained in:
Stenzek 2023-09-30 15:32:46 +10:00
parent 9f122ac0f0
commit 34aa419e92
2 changed files with 14 additions and 2 deletions

View file

@ -29,6 +29,9 @@ LogWindow::LogWindow(bool attach_to_main)
LogWindow::~LogWindow()
{
if (g_log_window == this)
g_log_window = nullptr;
Log::UnregisterCallback(&LogWindow::logCallback, this);
}
@ -39,7 +42,7 @@ void LogWindow::updateSettings()
const bool curr_enabled = (g_log_window != nullptr);
if (new_enabled == curr_enabled)
{
if (g_log_window->m_attached_to_main_window != attach_to_main)
if (g_log_window && g_log_window->m_attached_to_main_window != attach_to_main)
{
g_log_window->m_attached_to_main_window = attach_to_main;
if (attach_to_main)
@ -288,6 +291,12 @@ void LogWindow::logCallback(void* pUserParam, const char* channelName, const cha
}
}
void LogWindow::closeEvent(QCloseEvent* event)
{
// TODO: Update config.
QMainWindow::closeEvent(event);
}
void LogWindow::appendMessage(const QLatin1StringView& channel, quint32 level, const QString& message)
{
QTextCursor temp_cursor = m_text->textCursor();

View file

@ -5,9 +5,9 @@
#include "common/log.h"
#include <span>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QPlainTextEdit>
#include <span>
class LogWindow : public QMainWindow
{
@ -34,6 +34,9 @@ private:
static void logCallback(void* pUserParam, const char* channelName, const char* functionName, LOGLEVEL level,
std::string_view message);
protected:
void closeEvent(QCloseEvent* event);
private Q_SLOTS:
void onClearTriggered();
void onSaveTriggered();