Skip to content

juangburgos/QConsoleListener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published