An open API service indexing awesome lists of open source software.

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

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).