Octave plot from Qt C++ application

陌路散爱 提交于 2019-12-19 08:57:53

问题


I have a QT C++ application that runs the Octave program using QProcess. I am able to communicate with it by reading the standard output/error and writing to it's standard input using write method (for example: octave->write("5 + 5\n");).

As I told you I get response from octave (from the above example I get "ans = 10").

However, when the command I write to Octave standard input has a "plot" (for example, a simple plot([1 2 3 4 5]);), the actual graphic is never shown. I know Octave runs gnuplot, I have it installed, and gnuplot_x11 too. I even change the gnuplot binary path in my Octave process by executing gnuplot_binary("/usr/bin/gnuplot"); from MY APPLICATION. I know it runs good because if I retrieve the new value I get it right. But I don't know why Octave doesn't show the graphic.

Here I start octave:

QStringList arguments;
arguments << "--persist";
octave->setProcessChannelMode(QProcess::MergedChannels);
octave->start("/usr/bin/octave", arguments);

Here I write commands to octave process:

if (octave->state() == QProcess::Running) {
    QString command = widget.txtInput->toPlainText();
    if (command.isEmpty()) {
        return;
    }
    command += "\n";
    octave->write(command.toAscii());
}

With this I print the octave response to a text edit:

widget.txtOutput->append(octave->readAll() + "\n");

And finally, I use this when the octave process starts:

QString gnuplot_path(tr("\"/usr/bin/gnuplot\""));
QString gnuplot_cmd(tr("gnuplot_binary(%1)\n").arg(gnuplot_path));
octave->write(gnuplot_cmd.toAscii());

I will appreciate any help you could give me.

Thanks in advance.


回答1:


Octave, like Matlab, can be run in batch mode to perform computations without graphical UI. I assume that Octave detects that it is not run from an interactive session, and therefore automatically goes into batch mode. You would expect Octave to suppress graphical output (e.g. gnuplot output) when being in batch mode.

Try to force Octave into interactive mode by using the --interactive command line option: http://www.gnu.org/software/octave/doc/interpreter/Command-Line-Options.html




回答2:


I know you probably already solved your problem but this might be helpful for other... You can try to add a command to save your plot in a temporary folder in your octave request. Then display the graph in your ap



来源:https://stackoverflow.com/questions/5620259/octave-plot-from-qt-c-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!