简体   繁体   English

来自Qt C ++应用程序的Octave图

[英]Octave plot from Qt C++ application

I have a QT C++ application that runs the Octave program using QProcess. 我有一个使用QProcess运行Octave程序的QT C ++应用程序。 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");). 我可以通过读取标准输出/错误并使用write方法写入标准输入来与之通信(例如:octave-> write(“5 + 5 \\ n”);)。

As I told you I get response from octave (from the above example I get "ans = 10"). 正如我告诉你的那样,我从八度音中得到了回应(从上面的例子我得到“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. 但是,当我写入Octave标准输入的命令具有“绘图”(例如,简单绘图([1 2 3 4 5]);)时,实际图形从不显示。 I know Octave runs gnuplot, I have it installed, and gnuplot_x11 too. 我知道Octave运行gnuplot,我安装了它,还有gnuplot_x11。 I even change the gnuplot binary path in my Octave process by executing gnuplot_binary("/usr/bin/gnuplot"); 我甚至通过执行gnuplot_binary(“/ usr / bin / gnuplot”)来改变我的Octave过程中的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. 但我不知道为什么Octave没有显示图形。

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: 在这里我写命令到octave进程:

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. 提前致谢。

Octave, like Matlab, can be run in batch mode to perform computations without graphical UI. 与Matlab一样,Octave可以在批处理模式下运行,无需图形UI即可执行计算。 I assume that Octave detects that it is not run from an interactive session, and therefore automatically goes into batch mode. 我假设Octave检测到它不是从交互式会话中运行,因此会自动进入批处理模式。 You would expect Octave to suppress graphical output (eg gnuplot output) when being in batch mode. 当您处于批处理模式时,您会期望Octave抑制图形输出(例如gnuplot输出)。

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 尝试使用--interactive命令行选项强制Octave进入交互模式: http--interactive

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 然后在你的ap中显示图表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM