Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QConsoleListener

Small Qt library to handle console input asynchronously using signals and slots. Based on gjorquera's snippet.

Usage

Add to project in *.pro file

include($$PWD/src/qconsolelistener.pri)

Include the header #include <QConsoleListener> and connect to the QConsoleListener::newLine signal. For example:

#include <QCoreApplication>
#include <QDebug>

#include <QConsoleListener>

int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);

	// listen to console input
	QConsoleListener console;
	QObject::connect(&console, &QConsoleListener::newLine, 
	[&a](const QString &strNewLine) {
		qDebug() << "Echo :" << strNewLine;
		// quit
		if (strNewLine.compare("q", Qt::CaseInsensitive) == 0)
		{
			qDebug() << "Goodbye";
			a.quit();
		}
	});

	qDebug() << "Listening to console input:";
	return a.exec();
}

References

About

Small class to listen to console input asynchronously

Topics

Resources

Stars

44 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages