Using qt: How to create a Gui OnTop console application?

I have a console application created from bison (parser), and I want to create a simple gui for it so I can send the input from this gui to the console and get the console output in gui. I tried to do this using the java process class, but it does not work for me, please help me do this. using qt.

+6
qt bison console-application
source share
5 answers

It depends on the complexity of the data you want to submit to / from the console application.

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

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

Note. I made the assumption that you want your generated parsing analyzer to be separated from your Qt GUI (if necessary, to restore it again).

+4
source share

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

# Application template
TEMPLATE = application

# QMake configuration
CONFIG + = console

Then you can create a window in Qt and you will have your main window next to the console!

Example:

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

Hope this helps a bit!

+1
source share

Hold the console and graphics application with two separate applications. You already have a console, so let's see how to do another:

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

See the QProcess documentation for more details .

+1
source share

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

add first

 CONFIG += console 

to your .pro file

second use

 #include <stdio.h> QTextStream out(stdout); out << QString("Some text"); 

For me it works like this.

Good luck

+1
source share

Alternative: Tcl / TK

If you have no reason to use QT, it may be easier to use Tcl / Tk. Tcl was designed from the ground up to wrap scripts and GUI objects around existing C programs and is by far the easiest way to do this. It supports several different ways to integrate C code and Tk (the GUI toolkit that ships with Tcl / Tk) is short enough for programming and very easy to learn (think: one 2-hour lab in CS paper).

Tcl integration features:

  • Tcl can open a full-duplex channel for the program and exchange data through the pipe. By assumption, this is probably the best option for you.

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

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

  • Tcl has an API (also pretty simple) to extend the interpreter with new commands.

  • Perhaps one or two other ways that I cannot remember from my head.

0
source share

All Articles