A non-blocking Qt Style console class to easily handle stdin/out/err
- Based on QIODevice to allow easy integration
- Read from stdin via Qt without blocking the console
- Uses socket notifiers on UNIX
- Uses a parallel read thread on windows
- Shortcut methods to create QFile instances to stdin/out/err
The package is provided via qdep, as Skycoder42/QConsole
. To use it simply:
- Install and enable qdep (See qdep - Installing)
- Add the following to your pro file:
QDEP_DEPENDS += Skycoder42/QConsole
!load(qdep):error("Failed to load qdep feature! Run 'qdep.py prfgen --qmake $$QMAKE_QMAKE' to create it.")
Usage of this package is fairly simple. Create a consol instance and use it as any other QIODevice. The following is basically the demo, a small app the echoes anything you enter:
auto out = QConsole::qStdOut(&a);
QConsole console;
QObject::connect(&console, &QConsole::readyRead, [&](){
auto data = console.read(console.bytesAvailable());
out->write("Echo: " + data);
if(data.contains("exit"))
qApp->quit();
});
console.open();