GithubHelp home page GithubHelp logo

zjeffer / qtconsolelogger Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 23 KB

Qt Widget that uses a g3log sink to display log messages to the user

Dockerfile 9.01% Shell 4.50% CMake 18.11% C++ 68.37%
cpp qt qt6 qtcreator widget g3log

qtconsolelogger's Introduction

QtConsoleLogger

This is an example project for a Qt Console widget that receives log messages from 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 and adapted for use with g3log.

Basic usage

The main method:

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:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow{parent}, 
    m_Ui(new Ui::MainWindow) 
{
	// create a logger
	Logger logger = std::make_unique<Logger>(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(<LEVEL>) 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.hpp, and src/main.cpp.

qtconsolelogger's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.