TemporalBeing
28th August 2009, 22:25
I have a program where I am porting some old DOS code, and wrapping it in a Qt application.
The problem I have is that the DOS code makes extensive use of writing to stdout and stderr for its data, and I want to capture it all and put it into a QTextEdit.
I've noticed there is some functionality for this kind of thing _when_ running a child process via QProcess.
I came across a couple suggestions, but they are relatively old - one referred to KProcess, but that was a 1998 post (http://lists.trolltech.com/qt-interest/1998-05/msg00140.html), and the second suggested using QSocketNotifier (http://lists.trolltech.com/qt-interest/2002-01/thread00197-0.html) somehow.
I tried using the QSocketNotifier, but I never get any notices even though I know data has been written via printf(). Here's how I setup the access:
if (stdErrorReader == NULL)
{
stdErrorReader = new QFile(this);
if (stdErrorReader != NULL)
{
stdErrorReader->open(2,QIODevice::ReadOnly|QIODevice::Text);
connect(stdErrorReader,SIGNAL(readyRead()),this,SL OT(stdErrorDataAvailable()));
if (stdErrorNotifier == NULL)
{
stdErrorNotifier = new QSocketNotifier(2,QSocketNotifier::Read,this);
if (stdErrorNotifier != NULL)
{
connect(stdErrorNotifier,SIGNAL(activated(int)),th is,SLOT(stdErrorDataAvailable(int)));
}
}
}
}
if (stdOutReader == NULL)
{
stdOutReader = new QFile(this);
if (stdOutReader != NULL)
{
stdOutReader->open(1,QIODevice::ReadOnly|QIODevice::Text);
connect(stdOutReader,SIGNAL(readyRead()),this,SLOT (stdOutDataAvailable()));
if (stdOutNotifier == NULL)
{
stdOutNotifier = new QSocketNotifier(1,QSocketNotifier::Read,this);
if (stdOutNotifier != NULL)
{
connect(stdOutNotifier,SIGNAL(activated(int)),this ,SLOT(stdOutDataAvailable(int)));
}
}
}
}
The 'stdOutDataAvailable(int)' and 'stdOutDataAvailable()' slots never get called.
What am I doing wrong?
Is there a way to access the Application's QProcess() class so that I can use the methodology via QProcess?
The problem I have is that the DOS code makes extensive use of writing to stdout and stderr for its data, and I want to capture it all and put it into a QTextEdit.
I've noticed there is some functionality for this kind of thing _when_ running a child process via QProcess.
I came across a couple suggestions, but they are relatively old - one referred to KProcess, but that was a 1998 post (http://lists.trolltech.com/qt-interest/1998-05/msg00140.html), and the second suggested using QSocketNotifier (http://lists.trolltech.com/qt-interest/2002-01/thread00197-0.html) somehow.
I tried using the QSocketNotifier, but I never get any notices even though I know data has been written via printf(). Here's how I setup the access:
if (stdErrorReader == NULL)
{
stdErrorReader = new QFile(this);
if (stdErrorReader != NULL)
{
stdErrorReader->open(2,QIODevice::ReadOnly|QIODevice::Text);
connect(stdErrorReader,SIGNAL(readyRead()),this,SL OT(stdErrorDataAvailable()));
if (stdErrorNotifier == NULL)
{
stdErrorNotifier = new QSocketNotifier(2,QSocketNotifier::Read,this);
if (stdErrorNotifier != NULL)
{
connect(stdErrorNotifier,SIGNAL(activated(int)),th is,SLOT(stdErrorDataAvailable(int)));
}
}
}
}
if (stdOutReader == NULL)
{
stdOutReader = new QFile(this);
if (stdOutReader != NULL)
{
stdOutReader->open(1,QIODevice::ReadOnly|QIODevice::Text);
connect(stdOutReader,SIGNAL(readyRead()),this,SLOT (stdOutDataAvailable()));
if (stdOutNotifier == NULL)
{
stdOutNotifier = new QSocketNotifier(1,QSocketNotifier::Read,this);
if (stdOutNotifier != NULL)
{
connect(stdOutNotifier,SIGNAL(activated(int)),this ,SLOT(stdOutDataAvailable(int)));
}
}
}
}
The 'stdOutDataAvailable(int)' and 'stdOutDataAvailable()' slots never get called.
What am I doing wrong?
Is there a way to access the Application's QProcess() class so that I can use the methodology via QProcess?