Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding issue in qt_sinks #2862

Merged
merged 6 commits into from
Sep 9, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions include/spdlog/sinks/qt_sinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,23 @@ class qt_color_sink : public base_sink<Mutex>

const string_view_t str = string_view_t(formatted.data(), formatted.size());
// apply the color to the color range in the formatted message.
auto payload = QString::fromLatin1(str.data(), static_cast<int>(str.size()));
auto payload = QString::fromUtf8(str.data(), static_cast<int>(str.size()));
// convert color ranges from byte index to character index.
int color_range_start, color_range_end;
color_range_start = static_cast<int>(msg.color_range_start);
color_range_end = static_cast<int>(msg.color_range_end);
if (msg.color_range_start < msg.color_range_end) {
color_range_start = QString::fromUtf8(str.data(), msg.color_range_start).size();
color_range_end = QString::fromUtf8(str.data(), msg.color_range_end).size();
neothenil marked this conversation as resolved.
Show resolved Hide resolved
}

invoke_params params{max_lines_, // max lines
qt_text_edit_, // text edit to append to
std::move(payload), // text to append
default_color_, // default color
colors_.at(msg.level), // color to apply
static_cast<int>(msg.color_range_start), // color range start
static_cast<int>(msg.color_range_end)}; // color range end
color_range_start, // color range start
color_range_end}; // color range end

QMetaObject::invokeMethod(
qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);
Expand Down