使用 qt:如何在控制台应用程序之上构建 Gui?

发布于 2024-08-19 19:20:43 字数 147 浏览 2 评论 0原文

我有一个从 bison (解析器)生成的控制台应用程序,我想为其构建一个简单的 GUI 这样我就可以将此 gui 的输入发送到控制台,并将控制台的输出获取到 gui 中。 我尝试使用 java process 类来做到这一点,但它对我不起作用,请帮助我做到这一点 使用 qt 。

i have a console application that generated from bison (a parser) and i want to build a simple gui for it
so i can send input from this gui to the console and get output from the console into the gui .
i tried to do that using java process class but it doesnt work for me , please help me to do that
using qt .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我要还你自由 2024-08-26 19:20:43

这取决于您想要输入/输出控制台应用程序的数据的复杂性。

低复杂性
使用从 Qt GUI 传递到控制台应用程序的一些命令开关。查看QProcess 类文档

复杂性高
我会选择类似 RPC 的解决方案。查看 QtDBus 文档(仅限 Linux/Unix)。

注意:我假设您希望将生成的 bison 解析器与 Qt GUI 分开(以防您需要再次重新生成它)。

It depends on the complexity of the data you want to feed in/out of your console application.

Low complexity
Use some command switches that you pass from your Qt GUI to your console application. Look at the QProcess class documentation.

High complexity
I would go with an RPC-like solution. Look at the QtDBus documentation (Linux/Unix only).

Note: I made the assumption that you want to keep your generated bison parser apart from your Qt GUI (in case you need the regenerate it again).

提赋 2024-08-26 19:20:43

来自 http://www.qtcentre.org/threads /33506-where-is-cout-in-Qt-Creator

首先添加

CONFIG   += console 

到您的 .pro 文件

中,然后使用

#include <stdio.h>

  QTextStream out(stdout);
  out << QString("Some text");

对于我来说,它是这样工作的。

玩得开心

from http://www.qtcentre.org/threads/33506-where-is-cout-in-Qt-Creator

first add

CONFIG   += console 

to your .pro file

second use

#include <stdio.h>

  QTextStream out(stdout);
  out << QString("Some text");

For me it works this way.

Have fun

酒绊 2024-08-26 19:20:43

将控制台和图形应用程序保留为两个独立的应用程序。您已经有了一个控制台,所以让我们看看如何制作另一个:

在 Qt 中制作一个普通的 GUI 应用程序,并使用 QProcess 类调用您的控制台应用程序。使用 readData() 和 < a href="https://doc.qt.io/archives/4.6/qprocess.html#writeData" rel="nofollow noreferrer">writeData() (和类似的)方法此类从标准输出读取并写入控制台应用程序的标准输入。

有关详细信息,请查看 QProcess 文档。

Keep your console and your graphical application, two separated applications. You already have the console one, so let's see how to make the other:

Make a normal GUI application in Qt and, using the QProcess class, call your console application. Use the readData() and writeData() (and similar) methods of this class to read from standard output and write to standard input of your console application.

Check the QProcess documentation for details.

oО清风挽发oО 2024-08-26 19:20:43

我认为您必须将以下条目放入您的 .PRO 文件中:

\# Application template<br>
TEMPLATE = app

\# QMake configuration<br>
CONFIG  += console

然后您可以在 Qt 中创建一个窗口,并且您的主窗口将位于控制台旁边!

示例:

main.cpp
{
    QApplication App(argc, argv);
    ...
    MainFrm* pMainFrm = new MainFrm();
    pMainFrm->show();
    ...
    int ExitCode = App.exec();
    return ExitCode;
}

希望它能有所帮助!

I think you have to put the following entries in your .PRO file :

\# Application template<br>
TEMPLATE = app

\# QMake configuration<br>
CONFIG  += console

You can then create a Window in Qt, and you'll have your main window next to a console !

Example :

main.cpp
{
    QApplication App(argc, argv);
    ...
    MainFrm* pMainFrm = new MainFrm();
    pMainFrm->show();
    ...
    int ExitCode = App.exec();
    return ExitCode;
}

Hope it helps a bit !

白鸥掠海 2024-08-26 19:20:43

替代方案:Tcl/TK

除非您有充分的理由使用 QT,否则您可能会发现使用 Tcl/Tk。 Tcl 是从头开始设计的,用于将脚本和 GUI 工具封装在现有的 C 程序中,并且是迄今为止最简单的方法。它支持多种不同的方式来集成 C 代码和 Tk(Tcl/Tk 附带的 GUI 工具包),编程非常简洁,学习也非常简单(想想:一篇 CS 论文中的 2 小时实验)。

Tcl 集成功能:

  • Tcl 可以向程序打开全双工管道并沿管道进行通信。据猜测,这可能是您的最佳选择。

  • 您可以使用 fork/exec 来运行程序,并传递命令行参数。

  • 您还可以将 Tcl 解释器嵌入到您的 C 程序中;执行此操作的 API 非常简单。

  • Tcl 有 API(也很简单)用于使用新命令扩展解释器。

  • 可能还有一两种我一时想不起来的方式。

An alternative: Tcl/TK

Unless you have good reason to use QT you might find it easier to use Tcl/Tk. Tcl was designed from the ground up for wrapping scripting and GUI facilities around existing C programs and is by far the easiest way to do this. It supports quite a few different ways to integrate C code and Tk (the GUI toolkit shipped with Tcl/Tk) is quite concise to program and very simple to learn (think: one 2 hour lab in a CS paper).

Tcl integration features:

  • Tcl can open a full-duplex pipe to the program and communicate down the pipe. At a guess this is probably the best option for you.

  • You can use fork/exec to run the program, passing command line arguments.

  • You can also embed the Tcl interpreter in your C program; the API for doing this is dead simple.

  • Tcl has API's (also quite simple) for extending the interpreter with new commands.

  • Probably one or two other ways that I can't remember off the top of my head.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文