PDA

View Full Version : QProcess with Octave



timmu
15th October 2012, 12:13
I'd like to start QProcess to interact with Octave from within my code.
I never get any response because the process doesn't seem to be running. I suspect I'm using QProcess wrong.
Would you be able to help. Here's what I'm doing:



#include <QProcess>
#include "octave/oct.h"




QStringList arguments;
arguments << "--persist";
QProcess octave;
octave.setProcessChannelMode(QProcess::MergedChann els);
octave.start("/usr/bin/octave3.2", arguments);

if (octave.state() == QProcess::Running)
{

QString command = "1+2\n";
octave.write(command.toAscii());

QString answer; answer.append(octave.readAll() + "\n");
cout << "answer: " << command.toLocal8Bit().constData() << "\n";

}

octave.close();

ChrisW67
16th October 2012, 00:28
You assume that as soon as you write [11] Octave has read the command, processed it and returned a value before you try to read [13] i.e. you assume write is blocking. It cannot be blocking because it does not have any notion of what constitutes "finished" behaviour on the part of the controlled process. You need to either handle output as it is generated and announced by the QProcess object using a readyRead() signal, or use QIODevice::waitForReadyRead(). Be aware that the expected output may not arrive in one chunk.

Since you want to use Octave by using the "octave" process you should not need any includes from Octave.

wysota
16th October 2012, 00:50
i.e. you assume write is blocking.
...or that readAll() is blocking (and is going to return all data in one chunk).