Closed WorstCodeWay closed 3 years ago
Qt Widget is not guaranteed to work when operated from other than the GUI thread (usually the main thread). Logging from a different thread will crash it.
A workaround for the problem is provided by using the Qt event thread. See: https://doc.qt.io/qt-6/threads-synchronizing.html
Since spdlog::sinks::qt_sink
has been added to spdlog (#2018), why don't you try using it?
By the way.
If I remember correctly, the destructor of the parent Widget will also delete the child Widget, depending on the Qt design.
There is a bug in QSharedPtr
and delete ui;
which does a double delete.
@tt4g Thanks for quick reply.
I will look into and try spdlog::sinks::qt_sink
, but I wonder if this qt_sink
can support colorful message?
And I will read thread you introduced. I think it will help a lot.
This is a problem indeed.
I will be back soon after I have some progress.
And you make such great a work!
Change the color of QTextEdit
when the log is received by Qt slot function.
You should be able to add the log level as an argument with reference to 'spdlog::sinks::qt_sink'.
That qt_sinks
solved my problem. Learnt a lot! Thank you @tt4g.
I want to implement a log viewer in qt with
spdlog
. But the output log in QTextEdit is messed up in format while is well-formed in a log file. My codes are:MainWindow.h
MainWindow.cpp
Here is the core dump stack: