Aragorn
25th April 2007, 04:31
Hello,
I am relatively new to Qt, but so far I am enjoying it! I only hope someone has an idea what may be going wrong with my program...
I am using QProcess to start a process and capture its output. I am running WIN32 console applications, and in some cases, it works fine. For example, I can capture output from ipconfig, or ping, or whatever other command similar to those that I may want to capture.
The issue that I am having right now, however, is that not all programs are capable of being captured. I have access to another binary that if I execute by itself, I get output like I normally would. I can redirect it to a file using typical command line switches (> in this case)... but if I execute it using my program, it exits with a NormalStatus but with a Failed to Start code (added an if statement to check it in the ProcessedFinished function, not shown below), without any output. Several other binaries are the same way...
I have verified that it is not a permission issue, or a path issue for that matter. It isn't failing to start the process, it is producing the failed to start QProcess code in the ProcessFinished funtion but not before.
I don't know where to go from here, as I don't see anyone else having this problem if I search on the web. I am hoping someone here may be able to assist.
The section of code that I am having an issue with is below:
FlashDialog::FlashDialog(QWidget *parent):QDialog(parent)
{
setupUi(this);
connect(okButton,SIGNAL(clicked()),this,SLOT(close ()));
connect(&proc,SIGNAL(readyReadStandardOutput()),this,SLOT(r eadFromStdout()));
connect(&proc,SIGNAL(readyReadStandardError()),this,SLOT(re adFromStdErr()));
connect(&proc,SIGNAL(error(QProcess::ProcessError)),this,SL OT(processError(QProcess::ProcessError)));
connect(&proc,SIGNAL(finished(int,QProcess::ExitStatus)),th is,SLOT(processFinished(int,QProcess::ExitStatus)) );
}
void FlashDialog::setFilePath(QString filePath)
{
proc.start(filePath);
}
void FlashDialog::readFromStdout()
{
QByteArray newData=proc.readAllStandardOutput();
QString text=statusView->toPlainText() + QString::fromLocal8Bit(newData);
statusView->setPlainText(text);
}
void FlashDialog::readFromStdErr()
{
QByteArray newData=proc.readAllStandardError();
QString text=statusView->toPlainText() + QString::fromLocal8Bit(newData);
statusView->setPlainText(text);
}
void FlashDialog::processFinished(int exitCode,QProcess::ExitStatus exitStatus)
{
if(exitStatus==QProcess::CrashExit)
{
statusView->append("Program Crashed";);
}
}
void FlashDialog::enableOkButton()
{
}
void FlashDialog::processError(QProcess::ProcessError error)
{
if(error==QProcess::FailedToStart)
{
statusView->append("Failed to start";);
}
}
I am under somewhat of a time crunch, so any suggestions or help are greatly appreciated!
I am relatively new to Qt, but so far I am enjoying it! I only hope someone has an idea what may be going wrong with my program...
I am using QProcess to start a process and capture its output. I am running WIN32 console applications, and in some cases, it works fine. For example, I can capture output from ipconfig, or ping, or whatever other command similar to those that I may want to capture.
The issue that I am having right now, however, is that not all programs are capable of being captured. I have access to another binary that if I execute by itself, I get output like I normally would. I can redirect it to a file using typical command line switches (> in this case)... but if I execute it using my program, it exits with a NormalStatus but with a Failed to Start code (added an if statement to check it in the ProcessedFinished function, not shown below), without any output. Several other binaries are the same way...
I have verified that it is not a permission issue, or a path issue for that matter. It isn't failing to start the process, it is producing the failed to start QProcess code in the ProcessFinished funtion but not before.
I don't know where to go from here, as I don't see anyone else having this problem if I search on the web. I am hoping someone here may be able to assist.
The section of code that I am having an issue with is below:
FlashDialog::FlashDialog(QWidget *parent):QDialog(parent)
{
setupUi(this);
connect(okButton,SIGNAL(clicked()),this,SLOT(close ()));
connect(&proc,SIGNAL(readyReadStandardOutput()),this,SLOT(r eadFromStdout()));
connect(&proc,SIGNAL(readyReadStandardError()),this,SLOT(re adFromStdErr()));
connect(&proc,SIGNAL(error(QProcess::ProcessError)),this,SL OT(processError(QProcess::ProcessError)));
connect(&proc,SIGNAL(finished(int,QProcess::ExitStatus)),th is,SLOT(processFinished(int,QProcess::ExitStatus)) );
}
void FlashDialog::setFilePath(QString filePath)
{
proc.start(filePath);
}
void FlashDialog::readFromStdout()
{
QByteArray newData=proc.readAllStandardOutput();
QString text=statusView->toPlainText() + QString::fromLocal8Bit(newData);
statusView->setPlainText(text);
}
void FlashDialog::readFromStdErr()
{
QByteArray newData=proc.readAllStandardError();
QString text=statusView->toPlainText() + QString::fromLocal8Bit(newData);
statusView->setPlainText(text);
}
void FlashDialog::processFinished(int exitCode,QProcess::ExitStatus exitStatus)
{
if(exitStatus==QProcess::CrashExit)
{
statusView->append("Program Crashed";);
}
}
void FlashDialog::enableOkButton()
{
}
void FlashDialog::processError(QProcess::ProcessError error)
{
if(error==QProcess::FailedToStart)
{
statusView->append("Failed to start";);
}
}
I am under somewhat of a time crunch, so any suggestions or help are greatly appreciated!