PDA

View Full Version : connect a process for output (QT4)



icentenee
9th August 2006, 23:12
When connecting a QProcess executable (under Windows) to the readyReadStandardOutput signal, the slot function is never called.

The executable is running fine, as can be seen thru other outputs.

The slot function uses the readAllStandardOutput function, is running as a QThread
instance, but seemingly is not accessed by the QT event signalling system.

jacek
9th August 2006, 23:20
When connecting a QProcess executable (under Windows) to the readyReadStandardOutput signal, the slot function is never called.
May we see the connect statement?

Also add "CONFIG += console" to your .pro file, compile your application in debug mode and see whether there are any messages on the console.


The slot function uses the readAllStandardOutput function, is running as a QThread instance, but seemingly is not accessed by the QT event signalling system.
If you are connecting to a slot of object that lives in a different thread than the signal sender, make sure you use a direct connection (with proper synchronization mechanism) or that an event loop is running that thread.

icentenee
10th August 2006, 14:10
The connect statement is:
scenario = new QProcess;
scenario->start("./scen_1.exe");
connect(scenario, SIGNAL(readyReadStandardOutput()), this, SLOT(run()));

When putting run() in the same instance, nothing is output to the text widget again.
I got the cosole output option. No debug messages so far.
Are the .pro files used with MS VC++ ?

jacek
10th August 2006, 14:33
The connect statement is:[...]
Where did you place that? Does it happen to be in some method of QThread subclass?


When putting run() in the same instance, nothing is output to the text widget again.
Is this run() is QThread::run()?

icentenee
10th August 2006, 15:30
It's in the Dialog class (from QDialog). Only the Dialog instance is implemented.
I removed the QThread instance. run() is Dialog::run(), i.e. same instance.


Dialog::Dialog()
{
createMenu();
........................

setWindowTitle(tr("Run Scenario"));

scenario = new QProcess;
scenario->start("./scen_1.exe");
connect(scenario, SIGNAL(readyReadStandardOutput()), this, SLOT(run()));
if (!scenario->waitForStarted())
bigEditor->append(tr("Scenario start failed."));
else {
bigEditor->append(tr("Scenario started"));
}
}


void Dialog::run()
{
bigEditor->append(tr("read started"));
QString result_all = scenario->readAllStandardOutput();
bigEditor->append(tr(result_all.toAscii().data()));
}

jacek
10th August 2006, 16:12
Make sure Dialog::run() is listed in one of the "slots" sections and that you have Q_OBJECT macro within your class definition.

icentenee
10th August 2006, 16:46
thanks very much, it is working now.