Octave graph from Qt C ++ application

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

As I said, I get a response from an octave (from the above example, I get "ans = 10").

However, when the command I am writing for Octave standard input has a β€œgraph” (for example, a simple graph ([1 2 3 4 5]);), the actual graph is never displayed. I know that Octave launches gnuplot, I installed it and gnuplot_x11 too. I even change the gnuplot binary path in my Octave process by doing gnuplot_binary ("/ usr / bin / gnuplot"); from MY APPLICATION. I know that this works well, because if I get a new value, I get it right. But I do not know why Octave does not show graphics.

Here I start an octave:

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

Here I write the commands for the 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 an octave response to text editing:

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

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

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

I would be grateful for any help you could give me.

Thanks in advance.

+4
source share
2 answers

Octave, like Matlab, can be run in batch mode to perform calculations without a graphical interface. I assume that Octave detects that it does not start from an interactive session and therefore automatically goes into batch mode. You expect Octave to suppress graphics output (e.g. gnuplot output) when running in batch mode.

Try to force Octave to be activated interactively using the --interactive command line --interactive : http://www.gnu.org/software/octave/doc/interpreter/Command-Line-Options.html

+3
source

I know that you probably already solved your problem, but it can be useful for others ... You can try to add a command to save the plot in a temporary folder in your octave query. Then display the graph in ap

+1
source

Source: https://habr.com/ru/post/1347525/


All Articles