https://github.com/zjeffer/qtconsolelogger
Qt Widget that uses a g3log sink to display log messages to the user
https://github.com/zjeffer/qtconsolelogger
cpp g3log qt qt6 qtcreator widget
Last synced: about 2 months ago
JSON representation
Qt Widget that uses a g3log sink to display log messages to the user
- Host: GitHub
- URL: https://github.com/zjeffer/qtconsolelogger
- Owner: zjeffer
- Created: 2022-07-16T21:15:16.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-30T13:15:56.000Z (almost 4 years ago)
- Last Synced: 2025-02-13T09:46:21.797Z (over 1 year ago)
- Topics: cpp, g3log, qt, qt6, qtcreator, widget
- Language: C++
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# QtConsoleLogger
This is an example project for a Qt Console widget that receives log messages from [g3log](https://github.com/KjellKod/g3log).
I created a custom g3log sink that sends the logs to the widget. The widget itself (console.hpp & console.cpp) was copied from [here](https://code.qt.io/cgit/qt/qtserialport.git/tree/examples/serialport/terminal) and adapted for use with g3log.
## Basic usage
The main method:
```c++
int main(int argc, char** argv) {
// create an application
QApplication a(argc, argv);
// create a window:
MainWindow window = MainWindow();
window.show();
// start running
return a.exec();
}
```
Inside your custom window constructor:
```c++
MainWindow::MainWindow(QWidget *parent) :
QMainWindow{parent},
m_Ui(new Ui::MainWindow)
{
// create a logger
Logger logger = std::make_unique(this);
// Create a new Console object
Console console = Console();
// you can also create the logger in the constructor's initializer list,
// but I'm doing it like this to make it easier to understand.
// place the console where you want, for example as the central widget:
setCentralWidget(&console);
// connect the getData signal to the putData method
connect(m_Console, &Console::getData, m_Console, &Console::putData);
// Every time you use g3log's LOG() macro,
// it will print the message to both stdout and the GUI console:
LOG(INFO) << "Example";
}
```
For a full example on how to create a window with a console, see [src/mainwindow.cpp](src/mainwindow.cpp), [src/mainwindow.hpp](src/mainwindow.hpp), and [src/main.cpp](src/main.cpp).