Qt C ++应用程序的倍频程图 [英] Octave plot from Qt C++ application

查看:161
本文介绍了Qt C ++应用程序的倍频程图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QT C ++应用程序,它使用QProcess运行Octave程序.我可以通过读取标准输出/错误并使用write方法将其写入标准输入来与之通信(例如:octave-> write("5 + 5 \ n");).

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");).

正如我告诉你的那样,我从八度得到响应(从上面的示例中得到"ans = 10").

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

但是,当我写到Octave标准输入的命令带有绘图"(例如,简单绘图([1 2 3 4 5]);)时,实际的图形将永远不会显示.我知道Octave运行gnuplot,我已经安装了它,并且也安装了gnuplot_x11.我什至通过执行gnuplot_binary("/usr/bin/gnuplot");在我的Octave进程中更改gnuplot二进制路径.从我的应用程序.我知道它运行良好,因为如果检索新值,我会正确.但是我不知道为什么Octave不显示图形.

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.

我在这里开始八度:

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.

谢谢.

推荐答案

与Matlab一样,八度也可以以批处理模式运行,以执行不带图形UI的计算.我假设Octave检测到它不是从交互式会话运行的,因此自动进入批处理模式.在批处理模式下,您希望Octave抑制图形输出(例如gnuplot输出).

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.

尝试通过使用--interactive命令行选项将Octave强制进入交互模式: http://www.gnu.org/software/octave /doc/interpreter/Command-Line-Options.html

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

这篇关于Qt C ++应用程序的倍频程图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆