Here is the solution:
#include "qkReceptor.h"
// Qt includes
#include <qsocketnotifier>
#include <qtextstream>
#include <qtimer>
//=============================================================================
// Private
//=============================================================================
#include "qkReceptor_p.h"
qkReceptorPrivate::qkReceptorPrivate(qkReceptor * p)
: qkPrivate(p)
{
}
void qkReceptorPrivate::init()
{
Q_Q(qkReceptor);
q->start();
}
//=============================================================================
// Ctor / dtor
//=============================================================================
qkReceptor
::qkReceptor(QObject * parent
) : QThread(parent
), qkPrivatable
(new qkReceptorPrivate
(this)) {
Q_D(qkReceptor);
d->init();
}
qkReceptor::~qkReceptor()
{
}
//=============================================================================
// Protected QThread reimplementation
//=============================================================================
void qkReceptor::run()
{
// A timer to avoid high CPU charge
connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);
timer.start(100);
}
//=============================================================================
// Private slots
//=============================================================================
void qkReceptor::onCheckStdin()
{
// Do we have a new line to be read ?
if (line != "")
{
// Do something with our line
qkPrint(line.C_STR);
}
}
#include "qkReceptor.h"
// Qt includes
#include <qsocketnotifier>
#include <qtextstream>
#include <qtimer>
//=============================================================================
// Private
//=============================================================================
#include "qkReceptor_p.h"
qkReceptorPrivate::qkReceptorPrivate(qkReceptor * p)
: qkPrivate(p)
{
}
void qkReceptorPrivate::init()
{
Q_Q(qkReceptor);
q->start();
}
//=============================================================================
// Ctor / dtor
//=============================================================================
qkReceptor::qkReceptor(QObject * parent)
: QThread(parent), qkPrivatable(new qkReceptorPrivate(this))
{
Q_D(qkReceptor);
d->init();
}
qkReceptor::~qkReceptor()
{
}
//=============================================================================
// Protected QThread reimplementation
//=============================================================================
void qkReceptor::run()
{
// A timer to avoid high CPU charge
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(onCheckStdin()), Qt::DirectConnection);
timer.start(100);
QThread::exec();
}
//=============================================================================
// Private slots
//=============================================================================
void qkReceptor::onCheckStdin()
{
QTextStream stream(stdin);
// Do we have a new line to be read ?
QString line = stream.readLine();
if (line != "")
{
// Do something with our line
qkPrint(line.C_STR);
}
}
To copy to clipboard, switch view to plain text mode
If someone finds a proper way on windows, keep us posted.
Bookmarks