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, and the second suggested using QSocketNotifier 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:

Qt Code:
  1. if (stdErrorReader == NULL)
  2. {
  3. stdErrorReader = new QFile(this);
  4. if (stdErrorReader != NULL)
  5. {
  6. stdErrorReader->open(2,QIODevice::ReadOnly|QIODevice::Text);
  7. connect(stdErrorReader,SIGNAL(readyRead()),this,SLOT(stdErrorDataAvailable()));
  8. if (stdErrorNotifier == NULL)
  9. {
  10. stdErrorNotifier = new QSocketNotifier(2,QSocketNotifier::Read,this);
  11. if (stdErrorNotifier != NULL)
  12. {
  13. connect(stdErrorNotifier,SIGNAL(activated(int)),this,SLOT(stdErrorDataAvailable(int)));
  14. }
  15. }
  16. }
  17. }
  18. if (stdOutReader == NULL)
  19. {
  20. stdOutReader = new QFile(this);
  21. if (stdOutReader != NULL)
  22. {
  23. stdOutReader->open(1,QIODevice::ReadOnly|QIODevice::Text);
  24. connect(stdOutReader,SIGNAL(readyRead()),this,SLOT(stdOutDataAvailable()));
  25. if (stdOutNotifier == NULL)
  26. {
  27. stdOutNotifier = new QSocketNotifier(1,QSocketNotifier::Read,this);
  28. if (stdOutNotifier != NULL)
  29. {
  30. connect(stdOutNotifier,SIGNAL(activated(int)),this,SLOT(stdOutDataAvailable(int)));
  31. }
  32. }
  33. }
  34. }
To copy to clipboard, switch view to plain text mode 

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?