来自 Qt C++ 的倍频程图应用
我有一个 QT C++ 应用程序,它使用 QProcess 运行 Octave 程序。我可以通过读取标准输出/错误并使用 write 方法写入其标准输入(例如:octave->write("5 + 5\n");)来与它进行通信。
正如我告诉你的,我得到了来自八度的响应(从上面的例子中我得到“ans = 10”)。
然而,当我写入 Octave 标准输入的命令有一个“图”(例如,一个简单的图([1 2 3 4 5]);)时,实际的图形永远不会显示。我知道 Octave 运行 gnuplot,我已经安装了它,还有 gnuplot_x11。我什至通过执行 gnuplot_binary("/usr/bin/gnuplot"); 来更改 Octave 进程中的 gnuplot 二进制路径来自我的申请。我知道它运行良好,因为如果我检索新值,我就会得到正确的结果。但我不知道为什么 Octave 不显示图形。
在这里,我开始八度音程:
QStringList arguments;
arguments << "--persist";
octave->setProcessChannelMode(QProcess::MergedChannels);
octave->start("/usr/bin/octave", arguments);
在这里,我向八度音程过程编写命令:
if (octave->state() == QProcess::Running) {
QString command = widget.txtInput->toPlainText();
if (command.isEmpty()) {
return;
}
command += "\n";
octave->write(command.toAscii());
}
这样,我可以打印对文本编辑的八度音程响应:
widget.txtOutput->append(octave->readAll() + "\n");
最后,我在八度音程过程启动时使用它:
QString gnuplot_path(tr("\"/usr/bin/gnuplot\""));
QString gnuplot_cmd(tr("gnuplot_binary(%1)\n").arg(gnuplot_path));
octave->write(gnuplot_cmd.toAscii());
我将感谢您能给我的任何帮助。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Octave 与 Matlab 一样,可以以批处理模式运行,无需图形 UI 即可执行计算。我假设 Octave 检测到它不是从交互式会话运行,因此会自动进入批处理模式。您可能希望 Octave 在批处理模式下抑制图形输出(例如 gnuplot 输出)。
尝试使用
--interactive
命令行选项强制 Octave 进入交互模式:http://www.gnu.org/software/octave /doc/interpreter/Command-Line-Options.html
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
我知道您可能已经解决了您的问题,但这可能对其他人有帮助......
您可以尝试添加一个命令来将绘图保存在八度音阶请求的临时文件夹中。
然后在你的应用程序中显示图表
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