Merge pull request #7793 from spycrab/logging_async
Qt/LogWidget: Make logging asynchronous
This commit is contained in:
commit
e030a48741
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "Core/ConfigManager.h"
|
||||
|
||||
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
// Delay in ms between calls of UpdateLog()
|
||||
|
@ -188,6 +189,10 @@ void LogWidget::SaveSettings()
|
|||
|
||||
void LogWidget::Log(LogTypes::LOG_LEVELS level, const char* text)
|
||||
{
|
||||
// The text has to be copied here as it will be deallocated after this method has returned
|
||||
std::string str(text);
|
||||
|
||||
QueueOnObject(this, [this, level, str]() mutable {
|
||||
std::lock_guard<std::mutex> lock(m_log_mutex);
|
||||
|
||||
const char* color = "white";
|
||||
|
@ -211,12 +216,13 @@ void LogWidget::Log(LogTypes::LOG_LEVELS level, const char* text)
|
|||
break;
|
||||
}
|
||||
|
||||
std::string str(text);
|
||||
StringPopBackIf(&str, '\n');
|
||||
m_log_queue.push(QStringLiteral("%1 <span style=\"color: %2; white-space: pre\">%3</span>")
|
||||
m_log_queue.push(
|
||||
QStringLiteral("%1 <span style=\"color: %2; white-space: pre\">%3</span>")
|
||||
.arg(QString::fromStdString(str.substr(0, TIMESTAMP_LENGTH)),
|
||||
QString::fromStdString(color),
|
||||
QString::fromStdString(str.substr(TIMESTAMP_LENGTH)).toHtmlEscaped()));
|
||||
});
|
||||
}
|
||||
|
||||
void LogWidget::closeEvent(QCloseEvent*)
|
||||
|
|
Loading…
Reference in New Issue