-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Added common class for all qt objects #2018
Conversation
Removed separate class for qt_sinks and also send logs to any custom qt (QObject) classes (QML, QFile, custom Widget etc.)
include/spdlog/sinks/qt_sinks.h
Outdated
if (textedit != nullptr) { | ||
qtextedit_ = textedit; | ||
qt_sink(QObject *qt_object = nullptr, const std::string &meta_method = "") { | ||
if (qt_object != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont understand why to allow default nullptr in ctor if it get thrown afgerward if nullptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it doesn't matter(nullptr or qobject*) in last solution 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pass nullptr into QMetaObject::invokemethod function is valid but does nothing with nullptr. But with a valid QObject* object it will invoke a function named in meta_method string.
include/spdlog/sinks/qt_sinks.h
Outdated
meta_method_ = "append"; | ||
else if (std::is_same<T, QPlainTextEdit>::value) | ||
meta_method_ = "appendPlainText"; | ||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T is known at compile time, so template specialization should be used instead of the if statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will convert solution with template specialization
…bject Added factory funtion overloads for QTextEdit, QPlainTextEdit and QObject objects cleaned qt_sink ctor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned qt_sink ctor from unnecessary nullptr checks and added factory function overloads
Removed separate class layout for qt_sinks and also send logs to any custom qt (QObject) classes (QML, QFile, custom Widget etc.)